jwtk/jjwt · error · UnsupportedOperationException
Registries are immutable and cannot be modified.
Error message
Registries are immutable and cannot be modified.
What it means
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.
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.
Example fix
// before
registries.getAlgorithms().put("MYALG", myAlg); // UnsupportedOperationException
// after
Map<String, MyAlg> custom = new HashMap<>();
custom.put("MYALG", myAlg);
MyAlg alg = custom.containsKey(id) ? custom.get(id) : (MyAlg) registries.getAlgorithms().forKey(id); Defensive patterns
Strategy: try-catch
Try / catch
try {
registry.put(k, v);
} catch (UnsupportedOperationException e) {
// use the library's extension API or your own map instead
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- instance is immutable and may not be modified.
- JWKs are immutable and may not be modified.
- Not intended to be called.
- Not supported
- Unrecognized
AI-assisted analysis of jwtk/jjwt@fb71496164 (2026-09-09).
Data as JSON: /api/errors/4513852036dbaccf.
Report an issue: GitHub.
Appendix: source
Thrown at impl/src/main/java/io/jsonwebtoken/impl/lang/DefaultRegistry.java:66
}
@Override
public V apply(K k) {
return get(k);
}
@Override
public V forKey(K key) {
V value = get(key);
if (value == null) {
String msg = "Unrecognized " + this.qualifiedKeyName + ": " + key;
throw new IllegalArgumentException(msg);
}
return value;
}
static <T> T immutable() {
throw new UnsupportedOperationException("Registries are immutable and cannot be modified.");
}
@Override
public V put(K key, V value) {
return immutable();
}
@Override
public V remove(Object key) {
return immutable();
}
@Override
public void putAll(Map<? extends K, ? extends V> m) {
immutable();
}
@OverrideView on GitHub (pinned to fb71496164)