Skip to content

Commit

Permalink
Merge pull request jruby#8363 from headius/dedup_npe_race
Browse files Browse the repository at this point in the history
Ensure non-null reference when replacing
  • Loading branch information
headius authored Oct 9, 2024
2 parents c47402b + 2dec6f6 commit cfb1df8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -4895,7 +4895,9 @@ public RubyString freezeAndDedupString(RubyString string) {
// ref is there but vacated, try to replace it until we have a result
while (true) {
wrapper.string = string;
dedupedRef = dedupMap.computeIfPresent(wrapper, (key, old) -> old.get() == null ? weakref : old);

// re-get reference if it is non-null and populated, or replace with new reference
dedupedRef = dedupMap.compute(wrapper, (key, old) -> old == null || old.get() == null ? weakref : old);

// return result if not vacated
unduped = dedupedRef.get();
Expand Down

0 comments on commit cfb1df8

Please sign in to comment.