NullPointerException when prettyPrinting a KeyValuePair with null as value
A NullPointerException
is thrown when:
new KeyValuePair().setKey("key").setValue(null).prettyPrint();
Suggested fix in Printing.jrag
:
protected StringBuilder KeyValuePair.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (printIndent) sb.append(indent);
if (isCollapsed()) {
sb.append("\"");
}
sb.append(getKey());
if (isCollapsed()) {
sb.append("\"");
}
sb.append(":");
- if (getValue().isComplexElement() && !getValue().isEmpty() && !getValue().isCollapsed()) {
+ if (getValue() == null) {
+ sb.append(" null");
+ } else if (getValue().isComplexElement() && !getValue().isEmpty() && !getValue().isCollapsed()) {
sb.append("\n");
getValue().prettyPrint(sb, true, indent + PRINT_INDENT);
} else {
sb.append(" ");
getValue().prettyPrint(sb, false, indent);
}
return sb;
}