commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <Luc.Maison...@free.fr>
Subject Re: DescriptiveStatistics: addValue throws exception after clear
Date Mon, 20 Jul 2009 21:29:07 GMT
turicum a écrit :
> Hi everybody!
> 
> The following code throws an exception if x > 160
> 
> package test;
> import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
> public class Test {
> 	public static void main(String[] strings) {
> 		int x = 161; // 160 works
> 		DescriptiveStatistics descriptiveStatistics = new
> DescriptiveStatistics(100);
> 		for (int i = 0; i < x; i++) descriptiveStatistics.addValue(1.2);
> 		descriptiveStatistics.clear();
> 		descriptiveStatistics.addValue(1.2);
> 	}
> }
> 
> 
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32
> 	at
> org.apache.commons.math.util.ResizableDoubleArray.addElement(ResizableDoubleArray.java:255)
> 	at
> org.apache.commons.math.stat.descriptive.DescriptiveStatistics.addValue(DescriptiveStatistics.java:168)
> 	at test.Test.main(Test.java:11)
> 
> Am I missing anything?

This is a bug. The clear() method in ResizableDoubleArray did not reset
startIndex to 0.

I have fixed it in the subversion repository.

thanks for the report,
Luc

> Thanks!
> Alex
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message