[ https://issues.apache.org/jira/browse/MATH-1495?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16907134#comment-16907134 ]
Gilles commented on MATH-1495: ------------------------------ Thanks for pursuing this. bq. development version also has the same problem Then please submit a PR (and provide the link here). Note that the PR should be a single commit. But before that, please post a message to the "dev" ML to ensure that nobody objects to your proposed fix. Remarks about the [unit test code|https://github.com/apache/commons-math/compare/master...Kakarot-SSJ4:out-of-bounds]: * Field {{naturalranking}} should rather be a local variable, * method {{AllNaNArray}} should be renamed {{allNaNs}}. > Calling NaturalRanking#rank() on an array of all NaNs throws a misleading > ArrayIndexOutOfBoundsException when the NanStrategy is REMOVED > ---------------------------------------------------------------------------------------------------------------------------------------- > > Key: MATH-1495 > URL: https://issues.apache.org/jira/browse/MATH-1495 > Project: Commons Math > Issue Type: Bug > Reporter: Akash Srivastava > Priority: Major > > Consider the following code: > {code:java} > 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]); > } > } > {code} > 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: > {code:java} > 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) > {code} > > 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. -- This message was sent by Atlassian JIRA (v7.6.14#76016)