When EOF is encountered prematurely, Streams.parse() (and JsonParser) now throw JsonSyntaxException.

This commit is contained in:
Inderjeet Singh 2012-07-02 18:36:54 +00:00
parent 582b0a0c9c
commit 6575cdebca
2 changed files with 8 additions and 8 deletions

View File

@ -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) {

View File

@ -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() {