quarkusio/quarkus · error · UnsupportedOperationException
Not allowed to clear the context data map
Error message
Not allowed to clear the context data map
What it means
ContextDataMap backs ArcInvocationContext, the map passed to interceptor methods (InvocationContext.getContextData()). Clearing it wholesale would destroy framework-managed data such as the interceptor bindings, so ArC deliberately makes clear() unsupported and throws UnsupportedOperationException.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ContextDataMap.java:61
if (delegate == null) {
return Collections.emptyMap();
} else {
return delegate;
}
}
private Map<String, Object> getDelegateForWrite(final int sizeHint) {
if (delegate == null) {
this.delegate = new HashMap<>(sizeHint, 1.0f);
}
return delegate;
}
// ** Implement methods from the Map interface **
@Override
public void clear() {
throw new UnsupportedOperationException("Not allowed to clear the context data map");
}
@Override
public boolean containsKey(Object key) {
if (ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS.equals(key)) {
return true;
}
return getDelegateForRead().containsKey(key);
}
@Override
public boolean containsValue(Object value) {
if (interceptorBindings.equals(value)) {
return true;
}
return getDelegateForRead().containsValue(value);
}
View on GitHub (pinned to e1c734241f)
Solutions
- Remove the clear() call; instead remove only the specific keys you own with contextData.remove(yourKey).
- If you need a scratch area, create your own HashMap and use it instead of mutating the context data map.
- Iterate and delete only keys you placed into the map (avoiding KEY_INTERCEPTOR_BINDINGS).
Example fix
// before
contextData.clear();
// after
contextData.remove("my.custom.data.key"); Defensive patterns
Strategy: type-guard
Validate before calling
if (map instanceof ContextDataMap || ArcInvocationContext.class.isAssignableFrom(/* source */ Object.class)) {
// never call clear() on interceptor context data
} Type guard
static boolean isMutableRegularMap(Map<String, Object> m) {
return !(m instanceof ContextDataMap);
} Try / catch
try {
contextData.clear();
} catch (UnsupportedOperationException e) {
// context data is framework-managed: remove only own keys instead
} Prevention
- Treat InvocationContext.getContextData() as read-mostly framework state.
- Remove only keys you put in; never clear the whole map.
- Use a private HashMap for scratch data instead of the context map.
When it happens
Trigger: Calling contextData.clear() on the Map returned from InvocationContext.getContextData() inside an interceptor method (or via Map.clear() on any ContextDataMap reference).
Common situations: Generic utility code that 'resets' any map it receives (cleanup methods, generic cache eviction) being handed the interceptor context data; copying common map-manipulation patterns onto the CDI invocation context.
Related errors
- Not allowed to put key '${KEY_INTERCEPTOR_BINDINGS}' in the
- Not allowed to remove key '${KEY_INTERCEPTOR_BINDINGS}' from
- Unsupported injection point target: <injectionPoint>
- Interceptor class ${interceptorClass} is not a CDI bean. Onl
- Cannot find a @Transactional annotation
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/d153d5d37e6a3cdb.
Report an issue: GitHub.