When EOF is encountered prematurely, Streams.parse() (and JsonParser) now throw JsonSyntaxException.
This commit is contained in:
parent
582b0a0c9c
commit
6575cdebca
|
@ -50,10 +50,8 @@ public final class Streams {
|
|||
if (isEmpty) {
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
// We could possibly throw JsonSyntaxException since the stream prematurely ended.
|
||||
// However, it seems safe to throw JsonIOException since the source is an IOException.
|
||||
// Another reason is to maintain backward compatibility.
|
||||
throw new JsonIOException(e);
|
||||
// The stream ended prematurely so it is likely a syntax error.
|
||||
throw new JsonSyntaxException(e);
|
||||
} catch (MalformedJsonException e) {
|
||||
throw new JsonSyntaxException(e);
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -16,14 +16,16 @@
|
|||
|
||||
package com.google.gson;
|
||||
|
||||
import com.google.gson.common.TestTypes.BagOfPrimitives;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.CharArrayReader;
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.StringReader;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.google.gson.common.TestTypes.BagOfPrimitives;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
/**
|
||||
* Unit test for {@link JsonParser}
|
||||
*
|
||||
|
@ -42,7 +44,7 @@ public class JsonParserTest extends TestCase {
|
|||
try {
|
||||
parser.parse("[[]");
|
||||
fail();
|
||||
} catch (JsonParseException expected) { }
|
||||
} catch (JsonSyntaxException expected) { }
|
||||
}
|
||||
|
||||
public void testParseUnquotedStringArrayFails() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user