Skip to content

Commit

Permalink
Merge pull request #198 from inventage/improve-performance
Browse files Browse the repository at this point in the history
Instantiate exception only when required
  • Loading branch information
lbalmaceda authored Aug 29, 2017
2 parents 3f1472f + 804b1bb commit ba902e9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/src/main/java/com/auth0/jwt/impl/JWTParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ static ObjectMapper getDefaultObjectMapper() {

@SuppressWarnings("WeakerAccess")
<T> T convertFromJSON(String json, Class<T> tClazz) throws JWTDecodeException {
JWTDecodeException exception = new JWTDecodeException(String.format("The string '%s' doesn't have a valid JSON format.", json));
if (json == null) {
throw exception;
throw exceptionForInvalidJson(null);
}
try {
return mapper.readValue(json, tClazz);
} catch (IOException e) {
throw exception;
throw exceptionForInvalidJson(json);
}
}

private JWTDecodeException exceptionForInvalidJson(String json) {
return new JWTDecodeException(String.format("The string '%s' doesn't have a valid JSON format.", json));
}
}

0 comments on commit ba902e9

Please sign in to comment.