{"record":{"id":"7d3115dc354a3e32","repo":"quarkusio/quarkus","slug":"transformedannotationsbuilditem-queryformethodpara","errorCode":null,"errorMessage":"TransformedAnnotationsBuildItem#queryForMethodParam needs to operate on METHOD_PARAMETER AnnotationTarget","messagePattern":"TransformedAnnotationsBuildItem#queryForMethodParam needs to operate on METHOD_PARAMETER AnnotationTarget","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/TransformedAnnotationsBuildItem.java","lineNumber":82,"sourceCode":"        if (target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) {\n            // We cannot query Jandex for method param. annotation target, so we operate on the whole method\n            // and filter results accordingly\n            Collection<AnnotationInstance> result = new ArrayList<>();\n            for (AnnotationInstance instance : beanDeployment.getAnnotations(target.asMethodParameter().method())) {\n                if (instance.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)\n                        && instance.target().asMethodParameter().position() == target.asMethodParameter().position()) {\n                    result.add(instance);\n                }\n            }\n            return result;\n        } else {\n            return beanDeployment.getAnnotations(target);\n        }\n    }\n\n    private AnnotationInstance queryForMethodParam(AnnotationTarget target, DotName annotationName) {\n        if (!target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) {\n            throw new IllegalArgumentException(\n                    \"TransformedAnnotationsBuildItem#queryForMethodParam needs to operate on METHOD_PARAMETER AnnotationTarget\");\n        }\n        // We cannot query Jandex for method param. annotation target, so we operate on the whole method\n        // and filter results accordingly\n        for (AnnotationInstance instance : beanDeployment.getAnnotations(target.asMethodParameter().method())) {\n            if (instance.name().equals(annotationName)\n                    && instance.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)\n                    && instance.target().asMethodParameter().position() == target.asMethodParameter().position()) {\n                return instance;\n            }\n        }\n        return null;\n    }\n}\n","sourceCodeStart":64,"sourceCodeEnd":97,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/TransformedAnnotationsBuildItem.java#L64-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the AnnotationTarget passed is injectionPoint.getAnnotationTarget().asMethodParameter() (or check target.kind() == METHOD_PARAMETER first)","Use beanDeployment-based annotation queries or TransformedAnnotationsBuildItem.getAnnotations(target) for other kinds","Add a kind check in your build step before calling hasAnnotation/getAnnotation","If handling both fields and params, branch on target.kind() and use the appropriate API"],"exampleFix":"// before\nif (transformedAnnotations.hasAnnotation(target, DOTNAME_CONFIG_PROPERTY)) { ... }\n// after\nif (target.kind() == AnnotationTarget.Kind.METHOD_PARAMETER\n    && transformedAnnotations.hasAnnotation(target, DOTNAME_CONFIG_PROPERTY)) { ... }","handlingStrategy":"type-guard","validationCode":"if (target == null || target.kind() != AnnotationTarget.Kind.METHOD_PARAMETER) {\n    // use a different query API for class/method/field targets\n}","typeGuard":"static boolean isMethodParameter(AnnotationTarget t) {\n    return t != null && t.kind() == AnnotationTarget.Kind.METHOD_PARAMETER;\n}","tryCatchPattern":null,"preventionTips":["Check target.kind() before calling queryForMethodParam-based APIs","Branch per kind: CLASS/METHOD/FIELD vs METHOD_PARAMETER","Use getAnnotations(target) for generic lookups"],"tags":["cdi","jandex","annotations","build-time"],"backgroundTag":"invalid-annotation-target-kind","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}