Adds JSONException for write value errors #345
Merged
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.
What problem does this code solve?
This wraps exceptions that may occur during a write operation on JSONObject or JSONArray. The message include the key or index for which the error occured. This provides easier tracing for errors in log messages and exception stacks.
example log before the change:
Example after the change:
Risks
low. There would be some extra overhead on the stack traces, but really at this point in the code it resolves as a developer error. If these exceptions are being hit regularly in production code, the software has bigger problems than a little extra exception overhead.
In my case it was when I was trying to serialize a hibernate object outside of a hibernate session. In production systems, something like that should never happen. It happened to me because the error was thrown from an implementation of toString that was requesting a lazy-loaded object (which was unavailable because the object was detatched from a hibernate session)
Changes to the API?
No changes
Will this require a new release?
No, can be rolled into the next release
Should the documentation be updated?
No
Does it break the unit tests?
Yes. 1 test case failed because the error message is now wrapped. The test case has been updated and some test cases have been extended to increase code coverage.
see PR stleary/JSON-Java-unit-test#73
Was any code refactored in this commit?
Yes
Review status
ACCEPTED Starting 3 day comment window