diff --git a/gson/src/main/java/com/google/gson/internal/Streams.java b/gson/src/main/java/com/google/gson/internal/Streams.java index f49329d2..ad0b4bf2 100644 --- a/gson/src/main/java/com/google/gson/internal/Streams.java +++ b/gson/src/main/java/com/google/gson/internal/Streams.java @@ -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) { diff --git a/gson/src/test/java/com/google/gson/JsonParserTest.java b/gson/src/test/java/com/google/gson/JsonParserTest.java index f3012ca3..181d4ab7 100644 --- a/gson/src/test/java/com/google/gson/JsonParserTest.java +++ b/gson/src/test/java/com/google/gson/JsonParserTest.java @@ -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() {