Skip to content

Commit

Permalink
avoid NPE when value type is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Dec 13, 2022
1 parent be361f7 commit 167b8ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/main/java/org/grobid/core/data/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ public String toJson() {
} else
json.append(", ");
json.append("\"structure\" : " + getStructure().toJson() + ", ");
byte[] encodedParsedName = encoder.quoteAsUTF8(getStructure().toString());
String outputParsedName = new String(encodedParsedName);
json.append("\"parsed\" : \"" + outputParsedName + "\"");
if (getStructure().getType() != ValueBlock.Type.UNKNOWN) {
byte[] encodedParsedName = encoder.quoteAsUTF8(getStructure().toString());
String outputParsedName = new String(encodedParsedName);
json.append("\"parsed\" : \"" + outputParsedName + "\"");
}
}

if (offsets != null) {
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/grobid/core/data/ValueBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,12 @@ public String toJson() {
json.append("\"type\" : \"" + getType() + "\"");
if (!started) {
started = true;
} else
} else {
json.append(", ");
}


String valueAsString = toString();
if (valueAsString != null) {
byte[] encodedRawName = encoder.quoteAsUTF8(valueAsString);
if (getType() != Type.UNKNOWN) {
byte[] encodedRawName = encoder.quoteAsUTF8(toString());
String outputRawName = new String(encodedRawName);
if (!started) {
started = true;
Expand Down

0 comments on commit 167b8ac

Please sign in to comment.