Conversation
|
Looks like the intended behavior is for XML.toString(Object) to emit the string ""null"" on line 483 when the object is null. However, an NPE is thrown when line 472 is executed, so this never happens. The unit tests expose the bug, but this was not understood at the time. Proposal is to fix this by rearranging the flow of control so that when the object is null, line 472 is not executed but line 483 is executed. The unit tests will need to be updated for the new behavior. See https://github.com/stleary/JSON-Java-unit-test/tree/XML-npe-test-fix. |
|
What problem does this code solve? Changes to the API? Changes to how the code behaves? Does it break the unit tests? Will this require a new release? Should the documentation be updated? |
Fixes possible NullPointerException in XML.toString(object, tagName)
Fixes NPE in XML for pull request stleary#160 in the json-java project
The comparison for
(object == null) ? "null" : escape(object.toString())was doing nothing,escape(object.toString())would always be called sinceobjectcould never be null at this point. I have added a null check around the possible NPE areas so this check actually does something.If we want the NPE, then I propose we just change the
(object == null) ? "null" : escape(object.toString())tertiary toescape(object.toString())