Repository navigation
Conversation
| } | ||
| catch (EOFException ex) { | ||
| throw parseException("Empty input", jsonReader.toString()); | ||
| } |
There was a problem hiding this comment.
The jsonReader.peek() calls are outside gson.fromJson, so a syntax error they hit is not wrapped: gson throws MalformedJsonException (an IOException) and this branch turns it into RuntimeIOException. That happens for a bad first token (}) or bad trailing content ({"a":1} }, {"a":1},). Callers that catch JsonParseException miss it: riotcmd/json dies with a stack trace, and StoreParamsCodec.read (TDB1/TDB2) no longer ignores a broken tdb.cfg.
+import com.google.gson.stream.MalformedJsonException;
...
catch (EOFException ex) {
throw parseException("Empty input", jsonReader.toString());
}
+ catch (MalformedJsonException ex) {
+ throw parseException(null, ex.getMessage());
+ }
catch (IOException ex) {
IO.exception(ex);
return null;
}and a test in TestJson:
@Test
public void js_value_14() {
assertThrows(JsonParseException.class, ()->JSON.parse("}"));
assertThrows(JsonParseException.class, ()->JSON.parse("{\"a\":1} }"));
assertThrows(JsonParseException.class, ()->JSON.parse("{\"a\":1},"));
}There was a problem hiding this comment.
Further findings in https://gist.github.com/OyvindLGjesdal/51fc834b359dbcba1265f9f4218f5480
I wanted to comment inline since it is kind of a verbose wall of text, but I thought the content of the review looks relevant and could be useful.
GitHub issue resolved #4338
By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.