-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
None
-
None
-
Ruby Drivers
-
None
-
None
-
None
-
None
-
None
-
None
bson 5.2.0-java raises Java::JavaLang::InstantiationError on JRuby 10.1.2.0 (Ruby 4.0.0) when using BSON::ByteBuffer. This blocks our application's migration to JRuby 10.1.
Reproduction
With JRuby 10.1.2.0 and bson 5.2.0 installed:
require "bson"
b = BSON::ByteBuffer.new
b.put_int32(5)
p BSON::ByteBuffer.new(b.to_s).get_int32
Expected: 5
Actual:
Java::JavaLang::InstantiationError: org.jruby.RubyFixnum
Our application also encounters this error at org.bson_ruby.ByteBuf.getLength(ByteBuf.java:156).
Cause
JRuby 10.1 made org.jruby.RubyFixnum abstract as part of its LongFixnum/ShortFixnum implementation. The constructors remain declared, so existing compiled extensions link but fail when they attempt direct instantiation.
src/main/org/bson_ruby/ByteBuf.java directly constructs RubyFixnum at seven sites. The same calls are present in bson 5.2.0 and the inspected master source.
Proposed fix
Replace all seven constructor calls with the public RubyFixnum.newFixnum factory. For example:
// Before return new RubyFixnum(context.runtime, getLengthInternal()); // After return RubyFixnum.newFixnum(context.runtime, getLengthInternal());
RubyFixnum.newFixnum(Ruby, long) is also present in JRuby 9.2.9.0, 9.3.13.0 and 9.4.8.0.
Verification
We recompiled the patched ByteBuf against JRuby 10.1.2.0 and inserted it into the released bson 5.2.0 Java artifact.
Our Rails application's unit suite then passed: 4112 examples, 0 failures. With the unpatched artifact, the suite aborts before running examples.