[ https://issues.apache.org/jira/browse/MATH-1495?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16906308#comment-16906308 ]
Akash Srivastava edited comment on MATH-1495 at 8/13/19 3:19 PM: ----------------------------------------------------------------- I have cloned the Apache commons-math repository from github, precisely by the following URL: https://github.com/apache/commons-math.git was (Author: kakarotssj4): I have cloned the Apache commons math repository > 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)