konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.55k stars 260 forks source link

Fix/improve cloning of TreeMap and TreeSet objects #879

Closed tryone144 closed 5 months ago

tryone144 commented 5 months ago

This PR fixes the shallow clone of java.utils.TreeMap. Previously, the clone kept the reference to the same root node and in turn the whole tree. Modifications to the clone incorrectly also modified the original TreeMap. This update generates new tree nodes while keeping the key and value references, correctly making the clone independent.

Additionally, this PR includes a Clonable implementation for java.utils.TreeSet that follows the same logic of java.utils.HashSet.

konsoletyper commented 5 months ago

FYI: I encourage contributors to use var in their PR