{"record":{"id":"4513852036dbaccf","repo":"jwtk/jjwt","slug":"registries-are-immutable-and-cannot-be-modified","errorCode":null,"errorMessage":"Registries are immutable and cannot be modified.","messagePattern":"Registries are immutable and cannot be modified\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/lang/DefaultRegistry.java","lineNumber":66,"sourceCode":"    }\n\n    @Override\n    public V apply(K k) {\n        return get(k);\n    }\n\n    @Override\n    public V forKey(K key) {\n        V value = get(key);\n        if (value == null) {\n            String msg = \"Unrecognized \" + this.qualifiedKeyName + \": \" + key;\n            throw new IllegalArgumentException(msg);\n        }\n        return value;\n    }\n\n    static <T> T immutable() {\n        throw new UnsupportedOperationException(\"Registries are immutable and cannot be modified.\");\n    }\n\n    @Override\n    public V put(K key, V value) {\n        return immutable();\n    }\n\n    @Override\n    public V remove(Object key) {\n        return immutable();\n    }\n\n    @Override\n    public void putAll(Map<? extends K, ? extends V> m) {\n        immutable();\n    }\n\n    @Override","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/lang/DefaultRegistry.java#L48-L84","documentation":"DefaultRegistry is a read-only lookup structure; all mutating Map methods (put, remove, putAll, clear) delegate to immutable(), which unconditionally throws UnsupportedOperationException. Registries are populated once at library initialization and are intentionally unmodifiable.","triggerScenarios":"Calling put/remove/putAll/clear on a DefaultRegistry instance obtained from the library, e.g. trying to register a custom algorithm or codec by mutating the shared registry.","commonSituations":"Attempting runtime plugin-style registration of a custom JWA algorithm; test code trying to seed a registry; refactoring code that previously used a mutable HashMap into a registry.","solutions":["Don't mutate the registry - use the library's extension/SPI mechanisms for custom algorithms or codecs.","Keep your own Map for custom entries and consult it as a fallback when the registry lookup fails.","Copy needed entries into your own mutable map if you need a modified lookup table."],"exampleFix":"// before\nregistries.getAlgorithms().put(\"MYALG\", myAlg); // UnsupportedOperationException\n// after\nMap<String, MyAlg> custom = new HashMap<>();\ncustom.put(\"MYALG\", myAlg);\nMyAlg alg = custom.containsKey(id) ? custom.get(id) : (MyAlg) registries.getAlgorithms().forKey(id);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    registry.put(k, v);\n} catch (UnsupportedOperationException e) {\n    // use the library's extension API or your own map instead\n}","preventionTips":["Treat all registries as read-only singletons","Register custom algorithms via the library's supported extension points, not mutation","Maintain a separate Map for custom entries and merge lookups yourself"],"tags":["immutable","unsupported-operation","registry"],"backgroundTag":"unsupported-operation","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}