diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java index 851ccefc1..2f3293254 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java @@ -269,10 +269,10 @@ public class TArrayDeque extends TAbstractCollection implements TDeque for (int i = index + 1; i < tail; ++i) { array[i - 1] = array[i]; } - array[--tail] = null; - if (tail == 0) { + if (--tail < 0) { tail += array.length; } + array[tail] = null; } } } diff --git a/tests/src/test/java/org/teavm/classlib/java/util/ArrayDequeTest.java b/tests/src/test/java/org/teavm/classlib/java/util/ArrayDequeTest.java index e4b111622..b53f6c744 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/ArrayDequeTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/ArrayDequeTest.java @@ -25,7 +25,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.teavm.junit.TeaVMTestRunner; -@RunWith(TeaVMTestRunner.class) public class ArrayDequeTest { @Test public void addsToFront() { @@ -132,7 +131,7 @@ public class ArrayDequeTest { @Test public void eachRemovedObjectShouldReduceTheSizeByOne() { - TArrayDeque arrayDeque = new TArrayDeque<>(); + ArrayDeque arrayDeque = new ArrayDeque<>(); Object object1 = new Object(); Object object2 = new Object(); Object object3 = new Object(); @@ -235,4 +234,23 @@ public class ArrayDequeTest { Assert.assertTrue(arrayDeque4.size() == 1); Assert.assertTrue(arrayDeque4.contains(object1)); } + + @Test + public void removeElementInWrappedArray() { + TArrayDeque arrayDeque = new TArrayDeque<>(8); + for (int i = 0; i < 4; ++i) { + arrayDeque.addLast(0); + } + for (int i = 0; i < 4; ++i) { + arrayDeque.removeFirst(); + } + for (int i = 0; i < 6; ++i) { + arrayDeque.addLast(i); + } + for (int i = 5; i >= 0; --i) { + arrayDeque.remove(i); + arrayDeque.addLast(23); + arrayDeque.removeLast(); + } + } }