quarkusio/quarkus · error · DefinitionException

Invalid injection of Decorator<T> bean, can only be used in

Error message

Invalid injection of Decorator<T> bean, can only be used in decorators but was detected in: ${injectionPointInfo.getTargetInfo()}

What it means

Per the CDI spec, a Decorator<T> instance may only be injected into a decorator instance. ArC detects a Decorator<T> injection point inside a regular managed bean, synthetic bean, or producer method at build time and throws this DefinitionException.

Source

Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java:88

            // the container automatically detects the problem and treats it as a definition error.
            if (injectionPointInfo.getType().name().equals(DotNames.INTERCEPTOR_BEAN)) {
                throw new DefinitionException("Invalid injection of Interceptor<T> bean, can only be used in interceptors " +
                        "but was detected in: " + injectionPointInfo.getTargetInfo());
            }

            // If a Bean instance with qualifier @Intercepted is injected into a bean instance other than an interceptor
            // instance, the container automatically detects the problem and treats it as a definition error.
            if (injectionPointInfo.getType().name().equals(DotNames.BEAN)
                    && injectionPointInfo.getRequiredQualifier(DotNames.INTERCEPTED) != null) {
                throw new DefinitionException(
                        "Invalid injection of @Intercepted Bean<T>, can only be injected into interceptors " +
                                "but was detected in: " + injectionPointInfo.getTargetInfo());
            }

            // If a Decorator<T> instance is injected into a bean instance other than a decorator instance,
            // the container automatically detects the problem and treats it as a definition error.
            if (injectionPointInfo.getType().name().equals(DotNames.DECORATOR)) {
                throw new DefinitionException("Invalid injection of Decorator<T> bean, can only be used in decorators " +
                        "but was detected in: " + injectionPointInfo.getTargetInfo());
            }

            // If a Bean instance with qualifier @Decorated is injected into a bean instance other than a decorator
            // instance, the container automatically detects the problem and treats it as a definition error.
            if (injectionPointInfo.getType().name().equals(DotNames.BEAN)
                    && injectionPointInfo.getRequiredQualifier(DotNames.DECORATED) != null) {
                throw new DefinitionException(
                        "Invalid injection of @Decorated Bean<T>, can only be injected into decorators " +
                                "but was detected in: " + injectionPointInfo.getTargetInfo());
            }

            // the injection point is a field, an initializer method parameter or a bean constructor, with qualifier
            // @Default, then the type parameter of the injected Bean, or Interceptor must be the same as the type
            // declaring the injection point
            if (injectionPointInfo.getRequiredType().name().equals(DotNames.BEAN)
                    && injectionPointInfo.getRequiredType().kind() == Type.Kind.PARAMETERIZED_TYPE
                    && injectionPointInfo.getRequiredType().asParameterizedType().arguments().size() == 1

View on GitHub (pinned to e1c734241f)

Solutions

  1. Move the Decorator<T> injection point into a @Decorator class
  2. Apply the decoration via @Delegate inside a decorator instead of injecting Decorator<T> manually
  3. Remove the injection point if the metadata is unused

Example fix

// before
@ApplicationScoped class Svc { @Inject Decorator<Svc> decorator; }
// after
@Decorator abstract class SvcDecorator { @Inject Decorator<Object> decorator; @Delegate @Any Object delegate; }
Defensive patterns

Strategy: validation

Validate before calling

boolean ok = java.util.Arrays.stream(MyBean.class.getDeclaredFields())
    .noneMatch(f -> f.getType().getName().equals("jakarta.enterprise.inject.spi.Decorator"));

Prevention

When it happens

Trigger: Declaring @Inject Decorator<MyType> (or Instance<Decorator<...>>) in a normal bean, synthetic bean, or producer method rather than in a @Decorator class.

Common situations: Trying to enumerate or invoke decorators from business logic; copying metadata injection code from a decorator class into a service.

Related errors


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