Repository navigation
Java generator: raise TypeError for a String key whose to_s is broken - #1129
Merged
Merged
Conversation
When a Hash key is a String subclass, both generators call its to_s.
generator.c raises a TypeError in convert_string_subclass if to_s
doesn't return a String. The Java generator passed the result on, then
fell back to TypeConverter.convertToType, which returned the key itself
because it already is a String. So JSON.generate(s => 1) produced
{"test":1} on JRuby instead of raising.
Raise the same TypeError, with the same message, in castKey. The class
names go through to_s like PRIsVALUE does, so anonymous classes show as
#<Class:0x...> the way they do on CRuby.
This lets test_string_subclass_with_broken_to_s run on JRuby.
Part of ruby#1123
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On JRuby, a String subclass used as a Hash key whose
to_sdoesn't return a String is silently accepted:generator.craises inconvert_string_subclass. The Java generator passed the result ofto_son and then fell back toTypeConverter.convertToType, which returned the key unchanged because it already is a String.castKeynow raises the sameTypeErrorwith the same message. Class names go throughto_s, asPRIsVALUEdoes, so anonymous classes look the same as on CRuby. The pure-Ruby generator already raised aTypeError, so TruffleRuby needs no change.