quarkusio/quarkus · error · IllegalArgumentException

Contextual parameter must not be null

Error message

Contextual parameter must not be null

What it means

TransactionContext.get() validates its Contextual parameter and throws IllegalArgumentException("Contextual parameter must not be null") when null is passed. This guards the CDI SPI contract: the container must never pass a null Contextual; a null means a broken custom CDI extension or reflective misuse.

Source

Thrown at extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/context/TransactionContext.java:111

        } else {
            result = contextState;
        }
        return result;
    }

    @Override
    public Class<? extends Annotation> getScope() {
        return TransactionScoped.class;
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
        if (!isActive()) {
            throw new ContextNotActiveException();
        }
        if (contextual == null) {
            throw new IllegalArgumentException("Contextual parameter must not be null");
        }

        TransactionSynchronizationRegistry registryInstance = transactionSynchronizationRegistry.get();
        TransactionContextState contextState;

        // Prevent concurrent contextState creation from multiple threads sharing the same transaction,
        // since TransactionSynchronizationRegistry has no atomic compute if absent mechanism.
        transactionLock.lock();

        try {
            contextState = (TransactionContextState) registryInstance.getResource(TRANSACTION_CONTEXT_MARKER);

            if (contextState == null) {
                contextState = new TransactionContextState(getCurrentTransaction());
                registryInstance.putResource(TRANSACTION_CONTEXT_MARKER, contextState);
            }

        } finally {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass the actual Contextual instance obtained from the CDI container/BeanManager (e.g. beans.resolve, manager.createCreationalContext)
  2. Fix the custom extension/test code that passes null
  3. If introspecting, guard for null before calling get()

Example fix

// before
Object instance = context.get(null, creationalContext);
// after
Bean<T> bean = (Bean<T>) manager.resolve(manager.getBeans(type));
Object instance = context.get(bean, manager.createCreationalContext(bean));
Defensive patterns

Strategy: validation

Validate before calling

if (contextual == null) throw new IllegalArgumentException("Contextual parameter must not be null");

Type guard

boolean hasContextual(Contextual<?> c) { return c != null; }

Try / catch

try { v = ctx.get(contextual, cc); } catch (IllegalArgumentException e) { /* fix container/extension passing null Contextual */ }

Prevention

When it happens

Trigger: Directly calling TransactionContext (or a subclass/stand-in) .get(null, creationalContext) — typically from custom CDI extension code, tests, or reflection rather than normal application code.

Common situations: Custom CDI portable extensions or proxies invoking context APIs with unresolved beans; unit tests simulating the container and forgetting to build a real Contextual; framework misintegration.

Related errors


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