This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit c477140acaa10ad56c203dfc8209f657091f3a3d Author: Gary Gregory <[email protected]> AuthorDate: Tue Jan 27 20:26:56 2026 -0500 LANG-1816: ArrayUtils contains/indexOf/indexesOf with tolerance fail to match NaN values #1589 --- src/changes/changes.xml | 1 + .../java/org/apache/commons/lang3/ArrayUtils.java | 36 +++++++++++----------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index a6cb44170..138d36623 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -110,6 +110,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Ivan Ponomarev">Fix Javadoc in DoubleRange.of(Double, Double) to reflect actual exception type thrown #1581.</action> <action issue="LANG-1452" type="fix" dev="ggregory" due-to="Gary Gregory, Aleksey Novozhilov, Sara">RecursiveToStringStyle and MultilineRecursiveToStringStyle shouldn't recurse into a java.math.BigDecimal #1584.</action> <action issue="LANG-1814" type="fix" dev="ggregory" due-to="Ivan Ponomarev">ArrayUtils.subarray(..) may overflow index arithmetic and violate contract for extreme index values.</action> + <action issue="LANG-1816" type="fix" dev="ggregory" due-to="Ivan Ponomarev, Gary Gregory">ArrayUtils contains/indexOf/indexesOf with tolerance fail to match NaN values #1589.</action> <!-- ADD --> <action type="add" dev="ggregory" due-to="Gary Gregory">Add JavaVersion.JAVA_27.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_27.</action> diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 57f9da441..1faa21e5f 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -2877,24 +2877,6 @@ public static int indexOf(final double[] array, final double valueToFind, final return INDEX_NOT_FOUND; } - /** - * Finds the index of the NaN value in a double array. - * @param array the array to search for NaN, may be {@code null}. - * @param startIndex the index to start searching. - * @return the index of the NaN value within the array, {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input. - */ - private static int indexOfNaN(final double[] array, final int startIndex) { - if (isEmpty(array)) { - return INDEX_NOT_FOUND; - } - for (int i = max0(startIndex); i < array.length; i++) { - if (Double.isNaN(array[i])) { - return i; - } - } - return INDEX_NOT_FOUND; - } - /** * Finds the index of the given value in the array. * <p> @@ -3106,6 +3088,24 @@ public static int indexOf(final short[] array, final short valueToFind, final in return INDEX_NOT_FOUND; } + /** + * Finds the index of the NaN value in a double array. + * @param array the array to search for NaN, may be {@code null}. + * @param startIndex the index to start searching. + * @return the index of the NaN value within the array, {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input. + */ + private static int indexOfNaN(final double[] array, final int startIndex) { + if (isEmpty(array)) { + return INDEX_NOT_FOUND; + } + for (int i = max0(startIndex); i < array.length; i++) { + if (Double.isNaN(array[i])) { + return i; + } + } + return INDEX_NOT_FOUND; + } + /** * Inserts elements into an array at the given index (starting from zero). *
