From fe6e79663749c124d348083ef4284adfd0a422d9 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 11 Jun 2019 16:21:39 +0300 Subject: [PATCH] Fix bug in ArrayDeque --- .../java/org/teavm/classlib/java/util/TArrayDeque.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 591caddda..851ccefc1 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 @@ -262,11 +262,17 @@ public class TArrayDeque extends TAbstractCollection implements TDeque array[i + 1] = array[i]; } array[head++] = null; + if (head >= array.length) { + head = 0; + } } else { for (int i = index + 1; i < tail; ++i) { array[i - 1] = array[i]; } array[--tail] = null; + if (tail == 0) { + tail += array.length; + } } } } @@ -295,6 +301,9 @@ public class TArrayDeque extends TAbstractCollection implements TDeque return result; } @Override public void remove() { + if (lastIndex < 0) { + throw new IllegalStateException(); + } removeAt(lastIndex); lastIndex = -1; }