Skip to content

Commit ceba8e8

Browse files
author
John J. Aylward
committed
Fixes possible NPE
1 parent b0191a6 commit ceba8e8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

XML.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,23 +468,25 @@ public static String toString(Object object, String tagName)
468468
// XML does not have good support for arrays. If an array appears in a place
469469
// where XML is lacking, synthesize an <array> element.
470470

471-
} else {
471+
}
472+
if(object!=null){
472473
if (object.getClass().isArray()) {
473474
object = new JSONArray(object);
474475
}
476+
475477
if (object instanceof JSONArray) {
476478
ja = (JSONArray)object;
477479
length = ja.length();
478480
for (i = 0; i < length; i += 1) {
479481
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
480482
}
481483
return sb.toString();
482-
} else {
483-
string = (object == null) ? "null" : escape(object.toString());
484-
return (tagName == null) ? "\"" + string + "\"" :
485-
(string.length() == 0) ? "<" + tagName + "/>" :
486-
"<" + tagName + ">" + string + "</" + tagName + ">";
487484
}
488485
}
486+
string = (object == null) ? "null" : escape(object.toString());
487+
return (tagName == null) ? "\"" + string + "\"" :
488+
(string.length() == 0) ? "<" + tagName + "/>" :
489+
"<" + tagName + ">" + string + "</" + tagName + ">";
490+
489491
}
490492
}

0 commit comments

Comments
 (0)