Skip to content

Instantly share code, notes, and snippets.

@dwbutler
Last active December 11, 2015 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwbutler/4632270 to your computer and use it in GitHub Desktop.
Save dwbutler/4632270 to your computer and use it in GitHub Desktop.
Trying to reproduce a JSON.dump bug in JRuby
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
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)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment