Author: luc
Date: Mon Jul 20 21:27:12 2009
New Revision: 796021

URL: http://svn.apache.org/viewvc?rev=796021&view=rev
Log:
fixed an index error triggering ArrayIndexOutOfBoundException for an add after 
a clear
if size has grown

Modified:
    
commons/proper/math/trunk/src/java/org/apache/commons/math/util/ResizableDoubleArray.java
    
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/util/ResizableDoubleArray.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/ResizableDoubleArray.java?rev=796021&r1=796020&r2=796021&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/util/ResizableDoubleArray.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/util/ResizableDoubleArray.java
 Mon Jul 20 21:27:12 2009
@@ -375,6 +375,7 @@
      */
     public synchronized void clear() {
         numElements = 0;
+        startIndex = 0;
         internalArray = new double[initialCapacity];
     }
     

Modified: 
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java?rev=796021&r1=796020&r2=796021&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java
 Mon Jul 20 21:27:12 2009
@@ -75,6 +75,17 @@
             // expected
         }
     }
+
+    public void test20090720() {
+        DescriptiveStatistics descriptiveStatistics = new 
DescriptiveStatistics(100);
+        for (int i = 0; i < 161; i++) {
+            descriptiveStatistics.addValue(1.2);
+        }
+        descriptiveStatistics.clear();
+        descriptiveStatistics.addValue(1.2);
+        assertEquals(1, descriptiveStatistics.getN());
+    }
+
     public void testRemoval() {
 
         final DescriptiveStatistics dstat = createDescriptiveStatistics();


Reply via email to