quarkusio/quarkus · error · IllegalArgumentException

TransformedAnnotationsBuildItem#queryForMethodParam needs to

Error message

TransformedAnnotationsBuildItem#queryForMethodParam needs to operate on METHOD_PARAMETER AnnotationTarget

What it means

TransformedAnnotationsBuildItem.queryForMethodParam() looks up annotations on a method parameter by scanning the enclosing method's annotations (since Jandex cannot query parameter targets directly). It requires the given AnnotationTarget to be of kind METHOD_PARAMETER and throws IllegalArgumentException for any other kind.

Source

Thrown at extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/TransformedAnnotationsBuildItem.java:82

        if (target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) {
            // We cannot query Jandex for method param. annotation target, so we operate on the whole method
            // and filter results accordingly
            Collection<AnnotationInstance> result = new ArrayList<>();
            for (AnnotationInstance instance : beanDeployment.getAnnotations(target.asMethodParameter().method())) {
                if (instance.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)
                        && instance.target().asMethodParameter().position() == target.asMethodParameter().position()) {
                    result.add(instance);
                }
            }
            return result;
        } else {
            return beanDeployment.getAnnotations(target);
        }
    }

    private AnnotationInstance queryForMethodParam(AnnotationTarget target, DotName annotationName) {
        if (!target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) {
            throw new IllegalArgumentException(
                    "TransformedAnnotationsBuildItem#queryForMethodParam needs to operate on METHOD_PARAMETER AnnotationTarget");
        }
        // We cannot query Jandex for method param. annotation target, so we operate on the whole method
        // and filter results accordingly
        for (AnnotationInstance instance : beanDeployment.getAnnotations(target.asMethodParameter().method())) {
            if (instance.name().equals(annotationName)
                    && instance.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)
                    && instance.target().asMethodParameter().position() == target.asMethodParameter().position()) {
                return instance;
            }
        }
        return null;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the AnnotationTarget passed is injectionPoint.getAnnotationTarget().asMethodParameter() (or check target.kind() == METHOD_PARAMETER first)
  2. Use beanDeployment-based annotation queries or TransformedAnnotationsBuildItem.getAnnotations(target) for other kinds
  3. Add a kind check in your build step before calling hasAnnotation/getAnnotation
  4. If handling both fields and params, branch on target.kind() and use the appropriate API

Example fix

// before
if (transformedAnnotations.hasAnnotation(target, DOTNAME_CONFIG_PROPERTY)) { ... }
// after
if (target.kind() == AnnotationTarget.Kind.METHOD_PARAMETER
    && transformedAnnotations.hasAnnotation(target, DOTNAME_CONFIG_PROPERTY)) { ... }
Defensive patterns

Strategy: type-guard

Validate before calling

if (target == null || target.kind() != AnnotationTarget.Kind.METHOD_PARAMETER) {
    // use a different query API for class/method/field targets
}

Type guard

static boolean isMethodParameter(AnnotationTarget t) {
    return t != null && t.kind() == AnnotationTarget.Kind.METHOD_PARAMETER;
}

Prevention

When it happens

Trigger: Calling getAnnotation()/hasAnnotation() on a TransformedAnnotationsBuildItem with a target that is a class, method, or field rather than a method parameter — the internal queryForMethodParam path is reached with a wrong-kind target.

Common situations: Extension build-step code reusing a generic AnnotationTarget variable across different injection points; assuming hasAnnotation works uniformly for all target kinds; refactoring that changed the target's kind.

Related errors


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