Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
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
Closed

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'

puts JSON::VERSION

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

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

JSON.dump a HashWithIndifferentAccess #507

Florian Frank
Owner

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
View
@@ -10,3 +10,4 @@ Gemfile.lock
*.rbc
.rbx
.AppleDouble
+*.class
3  java/src/json/ext/GeneratorState.java
View
@@ -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
View
@@ -276,6 +276,7 @@ def to_s
def test_hash_likeness_set_symbol
state = JSON.state.new
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.