Skip to content

Clear removed values in IntMap - #1537

Merged
theigl merged 1 commit into
EsotericSoftware:masterfrom
CCCLL:fix-intmap-remove
Oct 21, 2026
Merged

theigl merged 1 commit into
EsotericSoftware:masterfrom
CCCLL:fix-intmap-remove

Conversation

@CCCLL

@CCCLL CCCLL commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #1536.

IntMap.remove and the remove method of its iterators cleared the key of a removed entry but not its value. So the map kept a reference to the value, eg to the Registration removed by DefaultClassResolver.unregister, containsValue still found it, findKey returned 0 for it, and after key 0 was removed with an iterator, put(0, value) returned it as the old value. The value is now set to null, like in ObjectMap and in libGDX's IntMap, which has the same implementation (libgdx/libgdx#6285).

get(0, defaultValue) returned null instead of the default value if the map had no key 0, since get was inlined in #876. It returns the default value again.

IntMapTest checks both. It fails when any of the four changes is reverted.

mvn -pl main test passes on JDK 8 (built with JDK 11), 11, 17, 21 and 25, and mvn -pl main formatter:validate passes. With the change applied to kryo-6, its tests pass on JDK 17, 21 and 25.

IntMap.remove and the remove method of its iterators cleared the key of
a removed entry but not its value. The map kept a reference to the
value, containsValue still found it, findKey returned 0 for it, and
after key 0 was removed with an iterator, put(0, value) returned it as
the old value.

Also, get(0, defaultValue) returned null instead of the default value if
the map had no key 0, since get was inlined in EsotericSoftware#876.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved issues were identified.

No open issues 🎉

What changed in this PR

Fixes IntMap stale-value retention and restores default handling for absent key 0.

Changes:

  • Clears values during direct and iterator removals.
  • Restores the supplied default for absent key 0.
  • Adds regression tests for both behaviors.
File Description
test/​com/​esotericsoftware/​kryo/​util/​IntMapTest.java Adds regression coverage for removals and default values.
src/​com/​esotericsoftware/​kryo/​util/​IntMap.java Corrects removal cleanup and default lookup behavior.

Review effort: Lite

@theigl
theigl merged commit 88abe53 into EsotericSoftware:master Oct 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

IntMap keeps removed values, and get(0, defaultValue) returns null

3 participants