[
https://issues.apache.org/jira/browse/LANG-1816?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ivan Ponomarev closed LANG-1816.
--------------------------------
> 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
> Priority: Minor
> Fix For: 3.21.0
>
>
> 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.0));
> // Also fail
> assertTrue(ArrayUtils.contains(a, Double.NaN, 0.0));
> assertTrue(ArrayUtils.indexesOf(a, Double.NaN, 0, 0.0).get(1));
> {code}
> h3.Proposed fix
> Add explicit NaN handling to the "tolerance" version of {{indexOf}}, similar
> to "non-tolerance" version
> See https://github.com/apache/commons-lang/pull/1589
--
This message was sent by Atlassian Jira
(v8.20.10#820010)