diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java index ef7a7263e..9263831d3 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java @@ -363,9 +363,9 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS while (minDepth > 0) { TreeNode node = pathToMin[--minDepth]; node.left = right; - right = node; node.fix(); - node.balance(); + node = node.balance(); + right = node; } min.right = right; min.left = left; diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java index 995a2af6b..868df7ab8 100644 --- a/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java @@ -639,4 +639,19 @@ public class TreeMapTest { } return treeMap; } + + @Test + public void deletesProperly() { + TreeMap tm = new TreeMap<>(); + for (int i = 0; i <= 100; ++i) { + tm.put(i, i); + } + for (int i = 0; i <= 100; ++i) { + Integer removed = tm.remove(i); + assertEquals(Integer.valueOf(i), removed); + tm.put(i, i + 1); + assertTrue("13 is expected to be in the map: " + i, tm.containsKey(13)); + assertTrue("99 is expected to be in the map: " + i, tm.containsKey(99)); + } + } }