Skip to content

Commit 6ed64ca

Browse files
authored
add multi-catch support to the code base (#2841)
1 parent 0074376 commit 6ed64ca

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

extras/src/main/java/com/google/gson/typeadapters/UtcDateTypeAdapter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,7 @@ private static Date parse(String date, ParsePosition pos) throws ParseException
223223
return calendar.getTime();
224224
// If we get a ParseException it'll already have the right message/offset.
225225
// Other exception types can convert here.
226-
} catch (IndexOutOfBoundsException e) {
227-
fail = e;
228-
} catch (NumberFormatException e) {
229-
fail = e;
230-
} catch (IllegalArgumentException e) {
226+
} catch (IndexOutOfBoundsException | IllegalArgumentException e) {
231227
fail = e;
232228
}
233229
String input = (date == null) ? null : ("'" + date + "'");

gson/src/main/java/com/google/gson/JsonParser.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,10 @@ public static JsonElement parseReader(Reader reader) throws JsonIOException, Jso
112112
throw new JsonSyntaxException("Did not consume the entire document.");
113113
}
114114
return element;
115-
} catch (MalformedJsonException e) {
115+
} catch (MalformedJsonException | NumberFormatException e) {
116116
throw new JsonSyntaxException(e);
117117
} catch (IOException e) {
118118
throw new JsonIOException(e);
119-
} catch (NumberFormatException e) {
120-
throw new JsonSyntaxException(e);
121119
}
122120
}
123121

@@ -144,9 +142,7 @@ public static JsonElement parseReader(JsonReader reader)
144142
}
145143
try {
146144
return Streams.parse(reader);
147-
} catch (StackOverflowError e) {
148-
throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e);
149-
} catch (OutOfMemoryError e) {
145+
} catch (StackOverflowError | OutOfMemoryError e) {
150146
throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e);
151147
} finally {
152148
reader.setStrictness(strictness);

gson/src/main/java/com/google/gson/JsonStreamParser.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ public JsonElement next() throws JsonParseException {
8787

8888
try {
8989
return Streams.parse(parser);
90-
} catch (StackOverflowError e) {
91-
throw new JsonParseException("Failed parsing JSON source to Json", e);
92-
} catch (OutOfMemoryError e) {
90+
} catch (StackOverflowError | OutOfMemoryError e) {
9391
throw new JsonParseException("Failed parsing JSON source to Json", e);
9492
}
9593
}

0 commit comments

Comments
 (0)