From abe244c099b8c0f0e4c33921a55b27755564713a Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Mon, 1 Nov 2010 22:48:52 +0000 Subject: [PATCH] renamed com.google.gson.stream.JsonSyntaxException to MalformedJsonException. Throwing JsonSyntaxException instead of JsonParseException where we can detect a syntax error. --- .../main/java/com/google/gson/DefaultTypeAdapters.java | 10 +++++----- .../main/java/com/google/gson/JsonStreamParser.java | 10 +++++++--- gson/src/main/java/com/google/gson/Streams.java | 8 ++++---- .../main/java/com/google/gson/stream/JsonReader.java | 2 +- ...yntaxException.java => MalformedJsonException.java} | 4 ++-- 5 files changed, 19 insertions(+), 15 deletions(-) rename gson/src/main/java/com/google/gson/stream/{JsonSyntaxException.java => MalformedJsonException.java} (88%) diff --git a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java index 8d2fd487..b82be520 100644 --- a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java +++ b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java @@ -278,7 +278,7 @@ final class DefaultTypeAdapters { return format.parse(json.getAsString()); } } catch (ParseException e) { - throw new JsonParseException(e); + throw new JsonSyntaxException(e); } } @@ -316,7 +316,7 @@ final class DefaultTypeAdapters { return new java.sql.Date(date.getTime()); } } catch (ParseException e) { - throw new JsonParseException(e); + throw new JsonSyntaxException(e); } } } @@ -351,7 +351,7 @@ final class DefaultTypeAdapters { return new Time(date.getTime()); } } catch (ParseException e) { - throw new JsonParseException(e); + throw new JsonSyntaxException(e); } } } @@ -425,7 +425,7 @@ final class DefaultTypeAdapters { try { return new URL(json.getAsString()); } catch (MalformedURLException e) { - throw new JsonParseException(e); + throw new JsonSyntaxException(e); } } @@ -444,7 +444,7 @@ final class DefaultTypeAdapters { try { return new URI(json.getAsString()); } catch (URISyntaxException e) { - throw new JsonParseException(e); + throw new JsonSyntaxException(e); } } @Override diff --git a/gson/src/main/java/com/google/gson/JsonStreamParser.java b/gson/src/main/java/com/google/gson/JsonStreamParser.java index 6f345da8..e4608e28 100644 --- a/gson/src/main/java/com/google/gson/JsonStreamParser.java +++ b/gson/src/main/java/com/google/gson/JsonStreamParser.java @@ -15,8 +15,6 @@ */ package com.google.gson; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; import java.io.EOFException; import java.io.IOException; import java.io.Reader; @@ -24,6 +22,10 @@ import java.io.StringReader; import java.util.Iterator; import java.util.NoSuchElementException; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.MalformedJsonException; + /** * A streaming parser that allows reading of multiple {@link JsonElement}s from the specified reader * asynchronously. @@ -101,8 +103,10 @@ public final class JsonStreamParser implements Iterator { synchronized (lock) { try { return parser.peek() != JsonToken.END_DOCUMENT; + } catch (MalformedJsonException e) { + throw new JsonSyntaxException(e); } catch (IOException e) { - throw new JsonParseException(e); + throw new JsonIOException(e); } } } diff --git a/gson/src/main/java/com/google/gson/Streams.java b/gson/src/main/java/com/google/gson/Streams.java index 79c3ba2b..73b00949 100644 --- a/gson/src/main/java/com/google/gson/Streams.java +++ b/gson/src/main/java/com/google/gson/Streams.java @@ -17,7 +17,7 @@ package com.google.gson; import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonSyntaxException; +import com.google.gson.stream.MalformedJsonException; import com.google.gson.stream.JsonWriter; import java.io.EOFException; @@ -71,12 +71,12 @@ final class Streams { } } catch (EOFException e) { return JsonNull.createJsonNull(); - } catch (JsonSyntaxException e) { - throw new JsonParseException(e); + } catch (MalformedJsonException e) { + throw new JsonSyntaxException(e); } catch (IOException e) { throw new JsonIOException(e); } catch (NumberFormatException e) { - throw new JsonParseException(e); + throw new JsonSyntaxException(e); } } diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index 09283100..a136b3bb 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -1104,7 +1104,7 @@ public final class JsonReader implements Closeable { * with this reader's content. */ private IOException syntaxError(String message) throws IOException { - throw new JsonSyntaxException(message + " near " + getSnippet()); + throw new MalformedJsonException(message + " near " + getSnippet()); } private CharSequence getSnippet() { diff --git a/gson/src/main/java/com/google/gson/stream/JsonSyntaxException.java b/gson/src/main/java/com/google/gson/stream/MalformedJsonException.java similarity index 88% rename from gson/src/main/java/com/google/gson/stream/JsonSyntaxException.java rename to gson/src/main/java/com/google/gson/stream/MalformedJsonException.java index af3d65f5..09c64250 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonSyntaxException.java +++ b/gson/src/main/java/com/google/gson/stream/MalformedJsonException.java @@ -22,8 +22,8 @@ import java.io.IOException; * Thrown when a reader encounters malformed JSON. Some syntax errors can be * ignored by calling {@link JsonReader#setLenient(boolean)}. */ -public final class JsonSyntaxException extends IOException { - public JsonSyntaxException(String s) { +public final class MalformedJsonException extends IOException { + public MalformedJsonException(String s) { super(s); } }