From 6575cdebca64244f400c86989a5b4957eb49d773 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Mon, 2 Jul 2012 18:36:54 +0000 Subject: [PATCH] When EOF is encountered prematurely, Streams.parse() (and JsonParser) now throw JsonSyntaxException. --- .../main/java/com/google/gson/internal/Streams.java | 6 ++---- gson/src/test/java/com/google/gson/JsonParserTest.java | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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() {