quarkusio/quarkus · error · IllegalStateException

Reflection invocation error

Error message

Reflection invocation error

What it means

FieldAccessor.getValue() reads a field reflectively via field.get(instance) and wraps any reflective failure (IllegalAccessException, NPE on null instance, IllegalArgumentException for wrong type) in an IllegalStateException with message "Reflection invocation error". It indicates the accessor could not read the field at runtime.

Source

Thrown at independent-projects/qute/core/src/main/java/io/quarkus/qute/FieldAccessor.java:23

/**
 *
 * @see ReflectionValueResolver
 */
class FieldAccessor implements ValueAccessor, AccessorCandidate {

    private final Field field;

    FieldAccessor(Field field) {
        this.field = field;
    }

    @Override
    public CompletionStage<Object> getValue(Object instance) {
        try {
            return CompletionStageSupport.toCompletionStage(field.get(instance));
        } catch (Exception e) {
            throw new IllegalStateException("Reflection invocation error", e);
        }
    }

    @Override
    public ValueAccessor getAccessor(EvalContext context) {
        return this;
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the class/field is registered for reflection when running in native mode (@RegisterForReflection or reflect-config.json).
  2. Check that the instance being evaluated is of the expected type and not null.
  3. In dev mode, trigger a clean restart so cached reflection accessors are rebuilt.
  4. Prefer generated value resolvers (compile-time) over reflection fallback by having proper bean classes/records accessible.

Example fix

// before (native image)
// no reflection config
// after
@RegisterForReflection
class MyDto { String name; }
// or add to reflect-config.json:
// {"name":"MyDto","allPublicFields":true}
Defensive patterns

Strategy: try-catch

Validate before calling

Field f = instance.getClass().getDeclaredField(name);
if (!f.isAccessible() /* or try setAccessible */) { /* register for reflection */ }

Type guard

boolean canReadReflectively(Object instance, String field) {
    if (instance == null) return false;
    try { instance.getClass().getDeclaredField(field); return true; }
    catch (NoSuchFieldException e) { return false; }
}

Try / catch

try {
    Object v = accessor.getValue(instance).toCompletableFuture().join();
} catch (IllegalStateException ex) {
    LOGGER.warn("reflective field read failed", ex.getCause());
    // fallback resolver or rethrow with context
}

Prevention

When it happens

Trigger: Value resolvers falling back to reflection (e.g. in dev mode, tests, or native image without generated accessors) when the field is not accessible, the instance is null, or the field's class was reloaded/changed (dev mode hot reload).

Common situations: Native-image builds missing reflection registration for the target class; dev-mode class redefinition invalidating cached Field objects; accessing a field on the wrong instance type.

Related errors


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