{"record":{"id":"8992ce9f5c24088d","repo":"prestodb/presto","slug":"failed-to-serialize-token-with-claims","errorCode":null,"errorMessage":"Failed to serialize token with claims","messagePattern":"Failed to serialize token with claims","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"presto-main/src/main/java/com/facebook/presto/server/security/oauth2/TokenPairSerializer.java","lineNumber":88,"sourceCode":"            LOG.debug(\"Using plain access token format (no claims available, will need to query on authentication)\");\n            return TokenPair.accessToken(token);\n        }\n\n        @Override\n        public String serialize(TokenPair tokenPair)\n        {\n            // If claims are present, serialize as Base64-encoded JSON with access token and claims\n            if (tokenPair.getClaims().isPresent()) {\n                try {\n                    Map<String, Object> data = new HashMap<>();\n                    data.put(\"accessToken\", tokenPair.getAccessToken());\n                    data.put(\"claims\", tokenPair.getClaims().get());\n                    String json = objectMapper.writeValueAsString(data);\n                    // Base64 encode to ensure cookie compatibility\n                    return Base64.getEncoder().encodeToString(json.getBytes(UTF_8));\n                }\n                catch (JsonProcessingException e) {\n                    throw new IllegalStateException(\"Failed to serialize token with claims\", e);\n                }\n            }\n\n            // Fallback: serialize as plain access token (backward compatibility)\n            return tokenPair.getAccessToken();\n        }\n    };\n\n    TokenPair deserialize(String token);\n\n    String serialize(TokenPair tokenPair);\n\n    class TokenPair\n    {\n        private final String accessToken;\n        private final Date expiration;\n        private final Optional<String> refreshToken;\n        private final Optional<Map<String, Object>> claims;","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main/src/main/java/com/facebook/presto/server/security/oauth2/TokenPairSerializer.java#L70-L106","documentation":"TokenPairSerializer.serialize failed while encoding the token pair plus its claims as Base64 JSON (JSON encoding error); serialization falls back to failing with this error since the cookie payload cannot be produced.","triggerScenarios":"Thrown at presto-main/src/main/java/com/facebook/presto/server/security/oauth2/TokenPairSerializer.java:88 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that claim values are JSON-serializable types","Report as a bug with the claim structure that triggered it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}