Skip to content

Commit 804b1bb

Browse files
committed
Don't instantiate unnecessary exception for valid JSON
1 parent 3f1472f commit 804b1bb

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/src/main/java/com/auth0/jwt/impl/JWTParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ static ObjectMapper getDefaultObjectMapper() {
4949

5050
@SuppressWarnings("WeakerAccess")
5151
<T> T convertFromJSON(String json, Class<T> tClazz) throws JWTDecodeException {
52-
JWTDecodeException exception = new JWTDecodeException(String.format("The string '%s' doesn't have a valid JSON format.", json));
5352
if (json == null) {
54-
throw exception;
53+
throw exceptionForInvalidJson(null);
5554
}
5655
try {
5756
return mapper.readValue(json, tClazz);
5857
} catch (IOException e) {
59-
throw exception;
58+
throw exceptionForInvalidJson(json);
6059
}
6160
}
61+
62+
private JWTDecodeException exceptionForInvalidJson(String json) {
63+
return new JWTDecodeException(String.format("The string '%s' doesn't have a valid JSON format.", json));
64+
}
6265
}

0 commit comments

Comments
 (0)