diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TLinkedList.java b/classlib/src/main/java/org/teavm/classlib/java/util/TLinkedList.java index 27ab9d7d6..3eafb601c 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TLinkedList.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TLinkedList.java @@ -95,17 +95,7 @@ public class TLinkedList extends TAbstractSequentialList implements TDeque @Override public boolean offer(E e) { - Entry entry = new Entry<>(); - entry.item = e; - entry.next = firstEntry; - if (firstEntry != null) { - firstEntry.previous = entry; - } else { - lastEntry = entry; - } - firstEntry = entry; - ++modCount; - ++size; + addLast(e); return true; } @@ -149,7 +139,17 @@ public class TLinkedList extends TAbstractSequentialList implements TDeque @Override public void addFirst(E e) { - offer(e); + Entry entry = new Entry<>(); + entry.item = e; + entry.next = firstEntry; + if (firstEntry != null) { + firstEntry.previous = entry; + } else { + lastEntry = entry; + } + firstEntry = entry; + ++modCount; + ++size; } @Override diff --git a/tests/src/test/java/org/teavm/classlib/java/util/LinkedListTest.java b/tests/src/test/java/org/teavm/classlib/java/util/LinkedListTest.java index 72dbd3131..83dbbbf3f 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/LinkedListTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/LinkedListTest.java @@ -308,4 +308,13 @@ public class LinkedListTest { lit.add("x"); assertEquals(List.of("d", "x", "a"), list); } + + @Test + public void offerOrder() { + var list = new LinkedList(); + list.offer("1"); + list.offer("2"); + assertEquals("1", list.getFirst()); + assertEquals("2", list.getLast()); + } }