Skip to content

Commit ba902e9

Browse files
authored
Merge pull request auth0#198 from inventage/improve-performance
Instantiate exception only when required
2 parents 3f1472f + 804b1bb commit ba902e9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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)