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

  1. Remove the clear() call; instead remove only the specific keys you own with contextData.remove(yourKey).
  2. If you need a scratch area, create your own HashMap and use it instead of mutating the context data map.
  3. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/d153d5d37e6a3cdb. Report an issue: GitHub.