From 804b1bbb87271424dad75e1be893f31e410e9114 Mon Sep 17 00:00:00 2001 From: Philippe Lovis Date: Mon, 28 Aug 2017 16:28:39 +0200 Subject: [PATCH] Don't instantiate unnecessary exception for valid JSON --- lib/src/main/java/com/auth0/jwt/impl/JWTParser.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/auth0/jwt/impl/JWTParser.java b/lib/src/main/java/com/auth0/jwt/impl/JWTParser.java index 1efb825e..45854785 100644 --- a/lib/src/main/java/com/auth0/jwt/impl/JWTParser.java +++ b/lib/src/main/java/com/auth0/jwt/impl/JWTParser.java @@ -49,14 +49,17 @@ static ObjectMapper getDefaultObjectMapper() { @SuppressWarnings("WeakerAccess") T convertFromJSON(String json, Class 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)); + } }