Skip to content

Use same key match for containsKey#9158

Merged
headius merged 1 commit intojruby:masterfrom
headius:fix_hashmapint_containskey
Jan 7, 2026
Merged

Use same key match for containsKey#9158
headius merged 1 commit intojruby:masterfrom
headius:fix_hashmapint_containskey

Conversation

@headius
Copy link
Member

@headius headius commented Jan 7, 2026

The containsKey method was never modified to support identity mode and will inccorrectly return true for distinct object keys that are equals and have the same identity hashcode. This led to bugs in Marshal.dump when many of the same value occurred in an object graph. containsKey would report that such an object was already in the link map, but a subsequent get of that key would produce -1 to be written to the dump. Later loading of that dump would error due to the invalid link index.

The fix here modifies containsKey to use the same matching logic as get, with awareness of identity comparison.

A test is included that will usually exercise the given logic, if it can produce a duplicate key object within a 5s timeout. If it cannot do that, it will no-op and skip the test. On my MacBook Air M4 with 10ish cores, it finds such a duplicate about 90% of the time.

Fixes #9152

@headius headius added this to the JRuby 10.0.3.0 milestone Jan 7, 2026
The containsKey method was never modified to support identity mode
and will inccorrectly return true for distinct object keys that are
equals and have the same identity hashcode. This led to bugs in
Marshal.dump when many of the same value occurred in an object
graph. containsKey would report that such an object was already in
the link map, but a subsequent get of that key would produce -1 to
be written to the dump. Later loading of that dump would error due
to the invalid link index.

The fix here modifies containsKey to use the same matching logic
as get, with awareness of identity comparison.

A test is included that will usually exercise the given logic, if
it can produce a duplicate key object within a 5s timeout. If it
cannot do that, it will no-op and skip the test. On my MacBook Air
M4 with 10ish cores, it finds such a duplicate about 90% of the
time.

Fixes jruby#9152
@headius headius force-pushed the fix_hashmapint_containskey branch from 274a5bb to cd239d3 Compare January 7, 2026 19:13
@headius headius merged commit 854beef into jruby:master Jan 7, 2026
76 checks passed
@headius headius deleted the fix_hashmapint_containskey branch January 7, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Marshal.dump corruption for large Array structures

1 participant