Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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

@jvshahid

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.

@jvshahid

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

@sluukkonen sluukkonen referenced this pull request in jruby/jruby
Closed

Update json to 1.7.6 #512

@edzhelyov

:+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)
@BanzaiMan BanzaiMan referenced this pull request in jruby/jruby
Closed

JSON.dump a HashWithIndifferentAccess #507

@flori
Owner

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

@flori 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. @jvshahid
  2. @jvshahid

    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.
View
1  .gitignore
@@ -10,3 +10,4 @@ Gemfile.lock
*.rbc
.rbx
.AppleDouble
+*.class
View
3  java/src/json/ext/GeneratorState.java
@@ -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;
}
}
View
1  tests/test_json_generate.rb
@@ -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.