diff --git a/src/java/org/apache/commons/math/util/ResizableDoubleArray.java b/src/java/org/apache/commons/math/util/ResizableDoubleArray.java index 0bcf76aa7..c55b99eb0 100644 --- a/src/java/org/apache/commons/math/util/ResizableDoubleArray.java +++ b/src/java/org/apache/commons/math/util/ResizableDoubleArray.java @@ -375,6 +375,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { */ public synchronized void clear() { numElements = 0; + startIndex = 0; internalArray = new double[initialCapacity]; } diff --git a/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java b/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java index c44bf24cf..c809875a4 100644 --- a/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java +++ b/src/test/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java @@ -75,6 +75,17 @@ public class DescriptiveStatisticsTest extends TestCase { // 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();