{"record":{"id":"e2a3c36c818573bf","repo":"jwtk/jjwt","slug":"cannot-create-date-from-value-cause","errorCode":null,"errorMessage":"Cannot create Date from '' value ''. Cause: ","messagePattern":"Cannot create Date from '' value ''\\. Cause: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/DefaultClaims.java","lineNumber":122,"sourceCode":"    public <T> T get(String claimName, Class<T> requiredType) {\n        Assert.notNull(requiredType, \"requiredType argument cannot be null.\");\n\n        Object value = this.idiomaticValues.get(claimName);\n        if (requiredType.isInstance(value)) {\n            return requiredType.cast(value);\n        }\n\n        value = get(claimName);\n        if (value == null) {\n            return null;\n        }\n\n        if (Date.class.equals(requiredType)) {\n            try {\n                value = JwtDateConverter.toDate(value); // NOT specDate logic\n            } catch (Exception e) {\n                String msg = \"Cannot create Date from '\" + claimName + \"' value '\" + value + \"'. Cause: \" + e.getMessage();\n                throw new IllegalArgumentException(msg, e);\n            }\n        }\n\n        return castClaimValue(claimName, value, requiredType);\n    }\n\n    private <T> T castClaimValue(String name, Object value, Class<T> requiredType) {\n\n        if (value instanceof Long || value instanceof Integer || value instanceof Short || value instanceof Byte) {\n            long longValue = ((Number) value).longValue();\n            if (Long.class.equals(requiredType)) {\n                value = longValue;\n            } else if (Integer.class.equals(requiredType) && Integer.MIN_VALUE <= longValue && longValue <= Integer.MAX_VALUE) {\n                value = (int) longValue;\n            } else if (requiredType == Short.class && Short.MIN_VALUE <= longValue && longValue <= Short.MAX_VALUE) {\n                value = (short) longValue;\n            } else if (requiredType == Byte.class && Byte.MIN_VALUE <= longValue && longValue <= Byte.MAX_VALUE) {\n                value = (byte) longValue;","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/DefaultClaims.java#L104-L140","documentation":"DefaultClaims.get(name, requiredType) converts date-like claim values (issued-at, expiration, etc.) from their stored numeric-seconds or ISO-8601 form into a java.util.Date via JwtDateConverter. If the stored value cannot be interpreted as a date, the converter throws and get() rethrows it as an IllegalArgumentException naming the claim and the underlying cause.","triggerScenarios":"Calling jwt.getBody().getExpiration()/getIssuedAt()/getNotBefore() (or get(name, Date.class)) when the corresponding claim in the JWT payload is not a valid date value — e.g. a string that is not ISO-8601, an unexpected object/array, or a non-numeric epoch value.","commonSituations":"Tokens minted by another library that serializes exp/iat/nbf as strings or nested objects; a corrupted or hand-edited token; a custom serializer writing claims in an unexpected format.","solutions":["Inspect the token payload (decode the JWT) to see the actual value of the named date claim and fix the issuer so it writes numeric epoch seconds or valid ISO-8601.","Parse the value yourself: read the raw claim via claims.get(name) and convert manually instead of requesting Date.class.","Wrap the get* call in try-catch for IllegalArgumentException and treat the token as invalid/untrusted.","If you control deserialization, register a custom JSON Deserializer via JwtParserBuilder.deserializer() that produces Date-compatible values."],"exampleFix":"// before\nDate exp = claims.getExpiration(); // throws\n// after\nObject raw = claims.get(\"exp\");\nDate exp = raw instanceof Number\n    ? new Date(((Number) raw).longValue() * 1000L)\n    : null;","handlingStrategy":"validation","validationCode":"Object v = claims.get(\"exp\");\nif (!(v instanceof Number) && !(v instanceof String)) throw new IllegalArgumentException(\"exp is not a date-like value: \" + v);","typeGuard":"boolean isDateLike(Object v) { return v instanceof Number || (v instanceof String s && !s.isBlank()); }","tryCatchPattern":"try { Date exp = claims.getExpiration(); } catch (IllegalArgumentException e) { /* treat token as invalid */ }","preventionTips":["Inspect raw JWT payloads of foreign-issued tokens before reading typed claims","Issue tokens with numeric epoch seconds for exp/iat/nbf","Add round-trip tests for token producers and consumers"],"tags":["jwt","claims","date-conversion"],"backgroundTag":"invalid-date-format","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}