Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


The Generator::State::op_href returns a raw java null when the given attribute is missing #155

wants to merge 2 commits into from

3 participants

John Shahid Evgeni Dzhelyov Florian Frank
John Shahid

Although the returned value compares to nil perfectly because JRuby do the conversion behind the scenes, calling anything on the returned object will cause a null pointer exception to be thrown.

This pull request includes a test to demonstrate the error and a fix for it.

John Shahid

ping. is there anything stopping this pr from being merged ?

Sakumatti Luukkonen sluukkonen referenced this pull request in jruby/jruby

Update json to 1.7.6 #512

Evgeni Dzhelyov

:+1: Please merge this PR.

1.7.6 doesn't fix the nullPointerException as you can test that with the following code

gem 'json', '=1.7.6'
require 'active_support/all'


h = { a: 1 }
puts JSON.dump(h)

hi =
puts JSON.dump(hi)
Hiro Asari BanzaiMan referenced this pull request in jruby/jruby

JSON.dump a HashWithIndifferentAccess #507

Florian Frank

This problem is now fixed in the current master, so you can check it out.

Florian Frank flori closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2013
  1. John Shahid
  2. John Shahid

    fix a bug in the JRuby implementation. getInstanceVariable() can retu…

    jvshahid authored
    …rn a null which causes NPE.
This page is out of date. Refresh to see the latest.
1  .gitignore
@@ -10,3 +10,4 @@ Gemfile.lock
3  java/src/json/ext/
@@ -263,7 +263,8 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject vName) {
if (getMetaClass().isMethodBound(name, true)) {
return send(context, vName, Block.NULL_BLOCK);
} else {
- return getInstanceVariables().getInstanceVariable("@" + name);
+ IRubyObject value = getInstanceVariables().getInstanceVariable("@" + name);
+ return value == null ? context.nil : value;
1  tests/test_json_generate.rb
@@ -276,6 +276,7 @@ def to_s
def test_hash_likeness_set_symbol
state =
assert_equal nil, state[:foo]
+ assert_equal nil.class, state[:foo].class
assert_equal nil, state['foo']
state[:foo] = :bar
assert_equal :bar, state[:foo]
Something went wrong with that request. Please try again.