Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work in JRuby (1.7.10 or 1.7.6) with --1.8 #95

Closed
dkowis opened this issue Jan 16, 2014 · 7 comments
Closed

Doesn't work in JRuby (1.7.10 or 1.7.6) with --1.8 #95

dkowis opened this issue Jan 16, 2014 · 7 comments

Comments

@dkowis
Copy link

dkowis commented Jan 16, 2014

I know this is like the edge case of edge cases, but I'm working on an old old old old application that is still stuck in Ruby 1.8 land because of SOAP stuff :( Trying to get it onto Jruby, so that I can do some measure of paralleizing and such taking advantage of the powerful JVM.

I haven't tested it in --1.9 because I can't run 1.9 mode with the old SOAP4R crap I have :(

I'm unable to run the validation logic:

Schema: https://gist.github.com/dkowis/9240d79f1126c8b495a1
Payload: https://gist.github.com/dkowis/ef2967f72571ecba06c3

turning these into JSON, and then calling
JSON::Validator.validate!(schema,payload,:validate_schema => true)

And I get this exception.

I'd push it up on a branch, but I can't run most of the other tests because they're using the new ruby 1.9 hash syntax, and that doesn't cooperate obviously. It should be very easy to duplicate using the data here.

RuntimeError: can't add a new key into hash during iteration
    org/jruby/RubyHash.java:971:in `[]='
    org/jruby/RubyHash.java:1773:in `replace'
    /home/dkowis/gitwork/json-schema/lib/json-schema/util/hash.rb:4:in `default_proc='
    /home/dkowis/gitwork/json-schema/lib/json-schema/schema.rb:45:in `add_indifferent_access'
    /home/dkowis/gitwork/json-schema/lib/json-schema/schema.rb:12:in `initialize'
    /home/dkowis/gitwork/json-schema/lib/json-schema/attributes/ref.rb:63:in `get_referenced_uri_and_schema'
    /home/dkowis/gitwork/json-schema/lib/json-schema/attributes/ref.rb:5:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:96:in `validate'
    org/jruby/RubyHash.java:1319:in `each'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:94:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/schema.rb:40:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/attributes/additionalproperties.rb:22:in `validate'
    org/jruby/RubyArray.java:1613:in `each'
    /home/dkowis/gitwork/json-schema/lib/json-schema/attributes/additionalproperties.rb:19:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:96:in `validate'
    org/jruby/RubyHash.java:1319:in `each'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:94:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/schema.rb:40:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/attributes/properties_v4.rb:24:in `validate'
    org/jruby/RubyHash.java:1319:in `each'
    /home/dkowis/gitwork/json-schema/lib/json-schema/attributes/properties_v4.rb:6:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:96:in `validate'
    org/jruby/RubyHash.java:1319:in `each'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:94:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/schema.rb:40:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:225:in `validate'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:176:in `initialize'
    /home/dkowis/gitwork/json-schema/lib/json-schema/validator.rb:395:in `validate!'
    /home/dkowis/gitwork/json-schema/test/test_complex_validation.rb:16:in `test_complex_validation'
    org/jruby/RubyKernel.java:2221:in `send'
    org/jruby/RubyArray.java:1613:in `each'
    org/jruby/RubyArray.java:1613:in `each'
@hoxworth
Copy link
Contributor

I'll take a look in the next couple of days - thanks! I do need to take some time and lock out the 1.9-specific tests when on 1.8. That seems to be an odd error to encounter, as 1.9 doesn't allow hash editing during iteration, and your schema/payload verify fine in MRI 1.9.3.

@dkowis
Copy link
Author

dkowis commented Jan 17, 2014

Looking at the sourcecode that throws the error: https://github.com/hoxworth/json-schema/blob/master/lib/json-schema/util/hash.rb
I see a different implementation in the backports gem:
https://github.com/marcandre/backports/blob/master/lib/backports/1.9.1/hash/default_proc.rb

I'm wondering if that's part of the problem, something isn't cooperating in there. I can try to use the backports implementation to update the Hash class and see if that makes it happy.

@hoxworth
Copy link
Contributor

Ahh, that's entirely possible. I didn't want to require the backports gem just to use json-schema with 1.8, but conflicts definitely could arise here. I'd rather use their implementation, to be honest, as long as it works cleanly. I'll test that out later this afternoon.

Thanks for digging!

@dkowis
Copy link
Author

dkowis commented Jan 17, 2014

So, for grins, I just added teh backport gem, and tried to use their implementation entirely.

Same error. I think it has to do with the schema.rb file, where the add_indifferent_access is happening, because it's modifying the hash during iteration (which is the error heh) so I don't think it's a backports problem, I think it's the way that hash is being updated to have indifferent access.

@hoxworth
Copy link
Contributor

Yep, and that's why 1.9 wouldn't have an issue, since that method is already defined. I'll clean that up.

@iainbeeston
Copy link
Contributor

This should be working now, partly because we test jruby on Travis (although admittedly in 1.9 mode, not 1.8) and partly because we've tidied up the test suite to run on Ruby 1.8. You will need to install the multi_json gem though (and a json parser that multi json supports)

@iainbeeston
Copy link
Contributor

I'm going to close this but please reopen if it's still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants