Use same key match for containsKey#9158
Merged
headius merged 1 commit intojruby:masterfrom Jan 7, 2026
Merged
Conversation
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
274a5bb to
cd239d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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