quarkusio/quarkus · error · IllegalStateException

Cannot obtain InjectionPoint metadata for non-@Dependent bea

Error message

Cannot obtain InjectionPoint metadata for non-@Dependent bean

What it means

Instance.select() in ArC returns an InjectableInstance; when selecting for the InjectionPoint type itself, wrap() throws IllegalStateException because InjectionPoint metadata can only be injected into @Dependent beans. Obtaining InjectionPoint for a non-@Dependent bean would give metadata for a shared bean instance, which the spec forbids.

Source

Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/InstanceImpl.java:84

            @Override
            public InjectableInstance<T> select(Annotation... qualifiers) {
                return wrap(null, delegate.select(qualifiers));
            }

            @Override
            public <U extends T> InjectableInstance<U> select(Class<U> subtype, Annotation... qualifiers) {
                return wrap(subtype, delegate.select(subtype, qualifiers));
            }

            @Override
            public <U extends T> InjectableInstance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers) {
                return wrap(subtype.getType(), delegate.select(subtype, qualifiers));
            }

            private <U> InjectableInstance<U> wrap(Type subtype, InjectableInstance<U> delegate) {
                if (InjectionPoint.class.equals(subtype)) {
                    throw new IllegalStateException("Cannot obtain InjectionPoint metadata for non-@Dependent bean");
                }
                return new Guard<>(delegate);
            }

            @Override
            public void clearCache() {
                delegate.clearCache();
            }

            @Override
            public Iterator<T> iterator() {
                return delegate.iterator();
            }

            @Override
            public boolean isUnsatisfied() {
                return delegate.isUnsatisfied();
            }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Only obtain InjectionPoint metadata from beans with @Dependent scope
  2. Inject InjectionPoint directly via @Inject into a @Dependent bean instead of selecting it from Instance
  3. Move the metadata-dependent logic into a separate @Dependent helper bean
  4. If you need the metadata in a normal-scoped bean, create the @Dependent helper via Instance<MyHelper>() and read InjectionPoint inside it

Example fix

// before (@ApplicationScoped bean)
@Inject Instance<InjectionPoint> ip;
InjectionPoint metadata = ip.get();
// after
dependingInstance.select(InjectionPoint.class).get(); // called on a @Dependent bean's Instance
Defensive patterns

Strategy: type-guard

Validate before calling

if (!beanClass.isAnnotationPresent(jakarta.enterprise.context.Dependent.class)) {
    throw new IllegalStateException("InjectionPoint metadata only available in @Dependent beans");
}

Type guard

static boolean canObtainInjectionPoint(Class<?> beanClass) {
    return beanClass.isAnnotationPresent(Dependent.class);
}

Try / catch

try {
    InjectionPoint ip = instance.select(InjectionPoint.class).get();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("non-@Dependent bean")) {
        throw new IllegalStateException("Move this logic to a @Dependent bean", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling instance.select(InjectionPoint.class) (or select(TypeLiteral<InjectionPoint>) ) programmatically on an Instance obtained in a bean whose scope is not @Dependent, e.g. @ApplicationScoped or @RequestScoped.

Common situations: Trying to inspect injection-point metadata at runtime from a singleton bean; copying code that worked in a @Dependent bean into a normal-scoped bean.

Related errors


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