public
Last active

Trying to reproduce a JSON.dump bug in JRuby

  • Download Gist
JSON_gem.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
rvm use jruby
gem install json
Successfully installed json-1.7.6-java
1 gem installed
 
# Uses JSON prepackaged with JRuby?
~ jruby -r 'json' -r 'active_support/hash_with_indifferent_access' -e "puts JSON::VERSION; puts JSON.dump HashWithIndifferentAccess.new"
1.7.5
{}
 
# Uses installed rubygem?
~ jruby -r 'rails/all' -r 'active_support/hash_with_indifferent_access' -r 'json' -e "puts JSON::VERSION; puts JSON.dump HashWithIndifferentAccess.new"
1.7.6
{}
 
# It looks like you have to actually initialize a Rails app before the error occurs
irb
irb(main):003:0> JRUBY_VERSION
=> "1.7.2"
 
require 'rails/all'
class Application < Rails::Application; end
Application.initialize!; nil
 
JSON::VERSION
=> "1.7.6"
 
puts JSON.dump HashWithIndifferentAccess.new
Java::JavaLang::NullPointerException:
from org.jruby.ast.IfNode.interpret(IfNode.java:115)
from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
from org.jruby.ast.IfNode.interpret(IfNode.java:116)
from org.jruby.ast.LocalAsgnNode.interpret(LocalAsgnNode.java:123)
from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
from org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
from org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
from org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:182)
from org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:188)
from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326)
from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
from org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57)
from org.jruby.ast.IfNode.interpret(IfNode.java:116)
from org.jruby.ast.DAsgnNode.interpret(DAsgnNode.java:110)
from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
from org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
... 194 levels...
from org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
from org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
from org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:182)
from org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:188)
from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326)
from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
from Users.davogones.$_dot_rvm.rubies.jruby_minus_1_dot_7_dot_2.bin.irb.__file__(/Users/davogones/.rvm/rubies/jruby-1.7.2/bin/irb:13)
from Users.davogones.$_dot_rvm.rubies.jruby_minus_1_dot_7_dot_2.bin.irb.load(/Users/davogones/.rvm/rubies/jruby-1.7.2/bin/irb)
from org.jruby.Ruby.runScript(Ruby.java:810)
from org.jruby.Ruby.runScript(Ruby.java:803)
from org.jruby.Ruby.runNormally(Ruby.java:674)
from org.jruby.Ruby.runFromMain(Ruby.java:523)
from org.jruby.Main.doRunFromMain(Main.java:390)
from org.jruby.Main.internalRun(Main.java:279)
from org.jruby.Main.run(Main.java:221)
from org.jruby.Main.main(Main.java:201)irb(main):004:0>
 
jruby -r'active_support/all' -e "puts JSON::VERSION; puts JSON.dump HashWithIndifferentAccess.new"
1.7.5
NoMethodError: undefined method `merge' for #<JSON::Ext::Generator::State:0x5b8ad9a0>
options_for at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:62
encode at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:47
check_for_circular_references at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:77
encode at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:46
encode at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:31
to_json at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/core_ext/object/to_json.rb:16
generate at json/ext/GeneratorState.java:210
generate at /Users/davogones/.rvm/rubies/jruby-1.7.2/lib/ruby/1.9/json/common.rb:223
dump at /Users/davogones/.rvm/rubies/jruby-1.7.2/lib/ruby/1.9/json/common.rb:387
(root) at -e:1
 
# Using the latest version of JSON from github master didn't help
➜ json git:(master) ✗ git remote -v
origin git@github.com:flori/json.git (fetch)
origin git@github.com:flori/json.git (push)
➜ json git:(master) ✗ jruby -Ilib -r'active_support/all' -e "puts JSON::VERSION; puts JSON.dump HashWithIndifferentAccess.new"
1.7.6
NoMethodError: undefined method `merge' for #<JSON::Ext::Generator::State:0x263534c1>
options_for at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:62
encode at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:47
check_for_circular_references at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:77
encode at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:46
encode at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:31
to_json at /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/core_ext/object/to_json.rb:16
generate at json/ext/GeneratorState.java:210
generate at /Users/davogones/Work/json/lib/json/common.rb:223
dump at /Users/davogones/Work/json/lib/json/common.rb:387
(root) at -e:1
JSON_master.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
rvm use jruby
git clone git@github.com:flori/json.git
cd json
bundle
 
json git:(master) irb -Ilib
irb(main):001:0> require 'json'
irb(main):002:0> JSON::VERSION
=> "1.7.6"
 
JRUBY_VERSION
=> "1.7.2"
 
require 'rails/all'
class Application < Rails::Application; end
Application.initialize!; nil
 
puts JSON.dump HashWithIndifferentAccess.new
NoMethodError: undefined method `merge' for #<JSON::Ext::Generator::State:0x551563a2>
from /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:62:in `options_for'
from /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:47:in `encode'
from /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
from /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:46:in `encode'
from /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:31:in `encode'
from /Users/davogones/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
from json/ext/GeneratorState.java:210:in `generate'
from /Users/davogones/Work/json/lib/json/common.rb:223:in `generate'
from /Users/davogones/Work/json/lib/json/common.rb:387:in `dump'
from (irb):7:in `evaluate'
from org/jruby/RubyKernel.java:1066:in `eval'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1174:in `catch'
from org/jruby/RubyKernel.java:1174:in `catch'
from /Users/davogones/.rvm/rubies/jruby-1.7.2/bin/irb:13:in `(root)'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.