Ivan Ponomarev created LANG-1816:
------------------------------------
Summary: ArrayUtils contains/indexOf/indexesOf with tolerance fail
to match NaN values
Key: LANG-1816
URL: https://issues.apache.org/jira/browse/LANG-1816
Project: Commons Lang
Issue Type: Bug
Reporter: Ivan Ponomarev
h3.Problem
Tolerance-based search for {{double}} arrays fails to match {{{}Double.NaN{}}},
even when the array contains {{{}NaN{}}}. This also affects {{contains}} and
{{indexesOf}} methods that delegate to the tolerance-based {{indexOf}}
implementation.
This is inconsistent with the non-tolerance overloads, where {{NaN}} is treated
as equal to {{NaN}} for search purposes.
{code:java}
final double[] a = {1, Double.NaN, 3};
// Works (non-tolerance path handles NaN explicitly)
assertEquals(1, ArrayUtils.indexOf(a, Double.NaN));
// Fails (tolerance path "forgets" about NaN)
assertEquals(1, ArrayUtils.indexOf(a, Double.NaN, 0.1));
// Also fail
assertTrue(ArrayUtils.contains(a, Double.NaN, 0.1));
assertTrue(ArrayUtils.indexesOf(a, Double.NaN, 0, 0.1).get(1));
{code}
h3.Proposed fix
Add explicit NaN handling to the "tolerance" version of {{indexOf}}, similar to
"non-tolerance" version
--
This message was sent by Atlassian Jira
(v8.20.10#820010)