Skip to content

Commit

Permalink
Fixes possible NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
John J. Aylward committed Oct 12, 2015
1 parent b0191a6 commit ceba8e8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions XML.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,25 @@ public static String toString(Object object, String tagName)
// XML does not have good support for arrays. If an array appears in a place
// where XML is lacking, synthesize an <array> element.

} else {
}
if(object!=null){
if (object.getClass().isArray()) {
object = new JSONArray(object);
}

if (object instanceof JSONArray) {
ja = (JSONArray)object;
length = ja.length();
for (i = 0; i < length; i += 1) {
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
}
return sb.toString();
} else {
string = (object == null) ? "null" : escape(object.toString());
return (tagName == null) ? "\"" + string + "\"" :
(string.length() == 0) ? "<" + tagName + "/>" :
"<" + tagName + ">" + string + "</" + tagName + ">";
}
}
string = (object == null) ? "null" : escape(object.toString());
return (tagName == null) ? "\"" + string + "\"" :
(string.length() == 0) ? "<" + tagName + "/>" :
"<" + tagName + ">" + string + "</" + tagName + ">";

}
}

0 comments on commit ceba8e8

Please sign in to comment.