quarkusio/quarkus · error · IllegalArgumentException
'target' can only be a class, a field or a method: <target>
Error message
'target' can only be a class, a field or a method: <target>
What it means
BuildTimeConditionBuildItem wraps the target of an @IfBuildTimeClass/@IfBuildTimeProfile-style annotation evaluation, and only CLASS, METHOD and FIELD annotation targets are supported. Any other AnnotationTarget.Kind (e.g. PARAMETER, TYPE) passed to the constructor throws IllegalArgumentException.
Source
Thrown at extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BuildTimeConditionBuildItem.java:20
import org.jboss.jandex.AnnotationTarget;
import io.quarkus.builder.item.MultiBuildItem;
public final class BuildTimeConditionBuildItem extends MultiBuildItem {
private final AnnotationTarget target;
private final boolean enabled;
public BuildTimeConditionBuildItem(AnnotationTarget target, boolean enabled) {
switch (target.kind()) {
case CLASS:
case METHOD:
case FIELD:
this.target = target;
break;
default:
throw new IllegalArgumentException("'target' can only be a class, a field or a method: " + target);
}
this.enabled = enabled;
}
public AnnotationTarget getTarget() {
return target;
}
public boolean isEnabled() {
return enabled;
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Only create the build item for CLASS, METHOD or FIELD targets
- Filter/ignore targets of other kinds before constructing the item
- Move the conditional annotation to a supported target (class/field/method)
Example fix
// before
conditions.produce(new BuildTimeConditionBuildItem(paramTarget, enabled));
// after
if (EnumSet.of(Kind.CLASS, Kind.METHOD, Kind.FIELD).contains(target.kind())) {
conditions.produce(new BuildTimeConditionBuildItem(target, enabled));
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!EnumSet.of(AnnotationTarget.Kind.CLASS, AnnotationTarget.Kind.METHOD, AnnotationTarget.Kind.FIELD).contains(target.kind())) { skip; } Type guard
boolean isSupportedTarget(AnnotationTarget t) {
return t.kind() == AnnotationTarget.Kind.CLASS
|| t.kind() == AnnotationTarget.Kind.METHOD
|| t.kind() == AnnotationTarget.Kind.FIELD;
} Prevention
- Check AnnotationTarget.kind() before constructing the item
- Only place @IfBuildXxx annotations on class/field/method
- Add unit tests for custom transformers covering all target kinds
When it happens
Trigger: Constructing BuildTimeConditionBuildItem with an AnnotationTarget whose kind is not CLASS, METHOD or FIELD — typically when a transformer/processor incorrectly forwards a parameter- or type-annotated target.
Common situations: Custom Arc transformers handling @IfBuildXxx annotations on method parameters or type uses and creating a build item from them; library upgrades changing where an annotation can be placed.
Related errors
- Name cannot start with '/':${name}
- messageStarts cannot be empty
- AnnotationTransformation is not an AnnotationsTransformer: <
- Invalid configuration value set for 'quarkus.arc.remove-unus
- Different default scopes defined for additional bean class:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/2792de6fa5f133d7.
Report an issue: GitHub.