-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Creating a JSONObject from a string that contains a duplicate key (any level) throws a JSONException that includes location #360
Conversation
@migueltt Thanks, will review and get back to you. This looks a little different than the code in the issue you opened a few days ago. Please explain why in your description. Also, if it was incorrect to use putOnce(), you don't need to comment why you are taking it out (i.e. its OK to remove those comment lines from the code). |
The previous pull request didn't consider the recursive constructor usage. Therefore, the syntaxError message was concatenated for every exception within the stack. |
It's also replacing flow control via exception with standard flow control. This matches with the other changes we made regarding using exceptions as flow control. This looks good to me if all the tests are passing. |
I may push another change tonight. I think we can call |
|
Ok we'll see... Problem is that the error location msg is off a few characters - right now is pointing to the key/value colon (:) |
Just a heads-up: Consistently including an error location in JSONExceptions during parsing is a reasonable enhancement. Tweaking the location pointer after the fact to try to get it exactly right without causing subtle regressions will probably be considered an unacceptable risk. |
This forces JSONTokener.syntaxError(..) to point to the last character of the duplicate key.
Adding |
What problem does this code solve? Risks Changes to the API? Will this require a new release? Should the documentation be updated? Does it break the unit tests? Was any code refactored in this commit? Review status Starting 3 day timer for comments |
For the first point, I agree that I'd rather not call @stleary, for your second point on the code changes, I believe @migueltt explained it here: #360 (comment) It was because of the way the constructor works with the tokener. It ends up being recursive calls instead of iterative. Maintaining the original The reason for not calling The null check on the |
In short, I think the only change I'd recommend is removing the call to back(); I don't think it adds any value to the error message here, and I'm wary of any potential problem it may cause due to lack of testing all possible data points. The other changes I agree with as they match the original functionality and they are only checking the map once to see if the key exists, where calling |
@johnjaylward Updated the review comment. |
Rationale to include
|
I think it's best to just remove the |
Sure, if that simplifies the whole JSON-java sdk/api, |
Review updated |
|
Constructor
JSONObject(JSONTokener)
has been updated to provide an error message that includes error location within the source string using local methodsyntaxError(String)
.JUnit test cases has been updated as well (see
org.json.unit.JSONObjectTest#jsonObjectParsingErrors()
)