Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JRuby 9.2 with unified Integer raises ClassCastException #336

Closed
headius opened this issue Jul 8, 2017 · 4 comments
Closed

JRuby 9.2 with unified Integer raises ClassCastException #336

headius opened this issue Jul 8, 2017 · 4 comments

Comments

@headius
Copy link
Contributor

headius commented Jul 8, 2017

We have been working on our Ruby 2.4 support for a release in the next couple months. Rubhy 2.4 unified Fixnum and Bignum into Integer, which means some APIs that only expected to get Fixnum or Bignum before might need to adapt to support both.

It appears that the JRuby extension has not been updated for that change yet. I get the following error in MRI's test_json.rb:

[ 3/32] TestJSON#test_big_integers = 0.01 s
  1) Error:
TestJSON#test_big_integers:
Java::JavaLang::ClassCastException: org.jruby.RubyBignum cannot be cast to org.jruby.RubyFixnum
    json.ext.Generator$2.generate(Generator.java:224)
    json.ext.Generator$4.generate(Generator.java:292)
    json.ext.Generator$4.generate(Generator.java:249)
    json.ext.Generator$Handler.generateNew(Generator.java:171)
    json.ext.Generator.generateJson(Generator.java:57)
    json.ext.GeneratorState.generate(GeneratorState.java:209)
    json.ext.GeneratorState$INVOKER$i$1$0$generate.call(GeneratorState$INVOKER$i$1$0$generate.gen)

Any place that assumes it will only receive Fixnums should probably be audited. I can help, but I assume this work was already done for the C ext, and the changes should be very similar for the Java ext.

@headius
Copy link
Contributor Author

headius commented Jul 8, 2017

See jruby/jruby#4293 for ongoing Ruby 2.4 work. The branch is ruby-2.4.

headius added a commit to jruby/jruby that referenced this issue Aug 3, 2017
kares added a commit to kares/json that referenced this issue Nov 28, 2018
slightly ugly but the only way to still compile under 1.7
once Ruby 1.9.3 gets dropped this should get ironed out !

resolves rubyGH-336
kares added a commit to kares/json that referenced this issue Jan 12, 2019
slightly ugly but the only way to still compile under 1.7
once Ruby 1.9.3 gets dropped this should get ironed out !

resolves rubyGH-336
@skarmakar
Copy link

skarmakar commented Feb 15, 2019

Seems like related

jruby-9.2.5.0 :010 > {"a" => 1, "b" => 12345678901234567890}.to_json
Traceback (most recent call last):
       16: from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:346)
       15: from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:141)
       14: from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:325)
       13: from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:191)
       12: from org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:793)
       11: from json.ext.GeneratorMethods$RbHash$INVOKER$s$0$0$to_json_DBG.call(GeneratorMethods$RbHash$INVOKER$s$0$0$to_json_DBG.gen)
       10: from json.ext.GeneratorMethods$RbHash.to_json(GeneratorMethods.java:70)
        9: from json.ext.Generator.generateJson(Generator.java:35)
        8: from json.ext.Generator$Handler.generateNew(Generator.java:171)
        7: from json.ext.Generator$5.generate(Generator.java:306)
        6: from json.ext.Generator$5.generate(Generator.java:333)
        5: from org.jruby.RubyHash.visitAll(RubyHash.java:2725)
        4: from org.jruby.RubyHash.visitLimited(RubyHash.java:690)
        3: from org.jruby.RubyHash$Visitor.visit(RubyHash.java:668)
        2: from json.ext.Generator$5$1.visit(Generator.java:354)
        1: from json.ext.Generator$2.generate(Generator.java:224)
Java::JavaLang::ClassCastException (org.jruby.RubyBignum cannot be cast to org.jruby.RubyFixnum)

which works perfectly with jruby 9.1.8, json (1.8.3 java)

jruby-9.1.8.0 :002 > {"a" => 1, "b" => 12345678901234567890}.to_json
 => "{\"a\":1,\"b\":12345678901234567890}" 

@flori flori closed this as completed in 81fbce0 Feb 21, 2019
@anup1710
Copy link

anup1710 commented Mar 27, 2019

Seems like this issue is not fully fixed.

require 'json'
JSON({"a": 1, "b": 23886820000238866000})

The above code causes same issue while parsing the hash into JSON. See the exception screenshot below.

image

@headius / @kares - I think this needs to be fixed.

@headius
Copy link
Contributor Author

headius commented Apr 11, 2019

We did not update json in time for the JRuby 9.2.7 release; please try to install the json gem. We will update it for 9.2.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants