Skip to content

Commit

Permalink
Emulate set.rb when hashing uninitialized Set
Browse files Browse the repository at this point in the history
set.rb is implemented in pure Ruby, so its @hash instance var will
start out as nil. If you attempt to #hash an uninitialized Set,
the resulting hashcode is that of nil, rather than raising an
exception as seen in jruby#8393.

This fix emulates the nil hash. No other uses of the uninitialized
Set are fixed here, so it's still largely unusable until it has
been initialized.

See also jruby#8352.

Fixes jruby#8393.
  • Loading branch information
headius committed Oct 30, 2024
1 parent ac0e933 commit 7f27f20
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ext/set/RubySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,13 @@ public boolean eql(IRubyObject other) {
@Override
@JRubyMethod
public RubyFixnum hash() { // @hash.hash
RubyHash hash = this.hash;

if (hash == null) {
// Emulate set.rb for jruby/jruby#8393
return ((RubyBasicObject) getRuntime().getNil()).hash();
}

return hash.hash();
}

Expand Down

0 comments on commit 7f27f20

Please sign in to comment.