From 7f27f205809f63dd3c315ae10dab4fb498423cfa Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 29 Oct 2024 21:38:36 -0500 Subject: [PATCH] Emulate set.rb when hashing uninitialized Set 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/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/jruby#8352. Fixes jruby/jruby#8393. --- core/src/main/java/org/jruby/ext/set/RubySet.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/main/java/org/jruby/ext/set/RubySet.java b/core/src/main/java/org/jruby/ext/set/RubySet.java index b49e344175e..63abd213648 100644 --- a/core/src/main/java/org/jruby/ext/set/RubySet.java +++ b/core/src/main/java/org/jruby/ext/set/RubySet.java @@ -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(); }