Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
None
Description
Consider the following code:
import org.apache.commons.math3.stat.ranking.NaNStrategy; import org.apache.commons.math3.stat.ranking.NaturalRanking; import org.apache.commons.math3.stat.ranking.TiesStrategy; class AllNaNException{ public NaturalRanking naturalranking; public double[] AllNaNArray(){ naturalranking = new NaturalRanking(NaNStrategy.REMOVED, TiesStrategy.AVERAGE); double[] x = {Double.NaN, Double.NaN}; double[] y = naturalranking.rank(x); return y; } public static void main(String[] args) { AllNaNException a = new AllNaNException(); double[] res = a.bug(); System.out.println(res[0] + "," + res[1]); } }
Compiled it by: javac -cp /usr/share/java/commons-math3-3.6.1.jar tryit.java
Executed it by: java -cp /usr/share/java/commons-math3-3.6.1.jar:. tryit
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at org.apache.commons.math3.stat.ranking.NaturalRanking.rank(NaturalRanking.java:231)
at tryit.bug(tryit.java:9)
at tryit.main(tryit.java:14)
Currently, calling NaturalRanking#rank() on an array of all NaNs throws a misleading ArrayIndexOutOfBoundsException when the NanStrategy is REMOVED. I am unsure what outcome the user should expect in code like the test case I have provided below. Can you shed some light on this? I am happy to write a pull request once I know what fix would be best. I think throwing an IllegalArgumentException or returning an empty array would be more apt in this case.