{"record":{"id":"b8a31faec44e366f","repo":"quarkusio/quarkus","slug":"invalid-annotation-target-for-templateglobal-an","errorCode":null,"errorMessage":"Invalid annotation target for @TemplateGlobal: <annotation>","messagePattern":"Invalid annotation target for @TemplateGlobal: <annotation>","errorType":"exception","errorClass":"io.quarkus.qute.TemplateException","httpStatus":null,"severity":"error","filePath":"extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java","lineNumber":3520,"sourceCode":"\n    @BuildStep\n    void collectTemplateGlobals(BeanArchiveIndexBuildItem beanArchiveIndex, BuildProducer<TemplateGlobalBuildItem> globals) {\n        IndexView index = beanArchiveIndex.getIndex();\n        Map<String, TemplateGlobalBuildItem> nameToGlobal = new HashMap<>();\n        for (AnnotationInstance annotation : index.getAnnotations(TemplateGlobalGenerator.TEMPLATE_GLOBAL)) {\n            switch (annotation.target().kind()) {\n                case CLASS:\n                    addGlobalClass(annotation.target().asClass(), nameToGlobal);\n                    break;\n                case FIELD:\n                    addGlobalField(annotation.value(TemplateGlobalGenerator.NAME), annotation.target().asField(), nameToGlobal);\n                    break;\n                case METHOD:\n                    addGlobalMethod(annotation.value(TemplateGlobalGenerator.NAME), annotation.target().asMethod(),\n                            nameToGlobal);\n                    break;\n                default:\n                    throw new TemplateException(\"Invalid annotation target for @TemplateGlobal: \" + annotation);\n            }\n        }\n        nameToGlobal.values().forEach(globals::produce);\n    }\n\n    private void addGlobalClass(ClassInfo clazz, Map<String, TemplateGlobalBuildItem> nameToGlobal) {\n        for (FieldInfo field : clazz.fields()) {\n            if (Modifier.isStatic(field.flags())\n                    && !Modifier.isPrivate(field.flags())\n                    && !field.isSynthetic()\n                    && !field.hasAnnotation(TemplateGlobalGenerator.TEMPLATE_GLOBAL)) {\n                addGlobalField(null, field, nameToGlobal);\n            }\n        }\n        for (MethodInfo method : clazz.methods()) {\n            if (Modifier.isStatic(method.flags())\n                    && !Modifier.isPrivate(method.flags())\n                    && method.returnType().kind() != org.jboss.jandex.Type.Kind.VOID","sourceCodeStart":3502,"sourceCodeEnd":3538,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java#L3502-L3538","documentation":"Thrown when @TemplateGlobal is found on an element other than a class, field, or method (e.g. a parameter or constructor). Qute only processes @TemplateGlobal on types, fields producing global variables, and static methods producing computed globals.","triggerScenarios":"Annotating a constructor or method parameter with @TemplateGlobal; a custom annotation meta-annotated with @TemplateGlobal whose target resolves to an unsupported element kind in the processor's switch (CLASS/METHOD handled, default throws).","commonSituations":"Misreading @TemplateGlobal as a CDI qualifier and putting it on injection points; IDE auto-completion applying it to parameters; refactorings that moved the annotation down to a parameter.","solutions":["Apply @TemplateGlobal only to a class, a field, or a supported static method","For a computed global, use a public static method annotated with @TemplateGlobal (optionally with @TemplateGlobal.Enum for params)","Remove the annotation from the unsupported element","Make sure a meta-annotated custom annotation's @Target restricts to TYPE, FIELD, METHOD"],"exampleFix":"// before\nclass Globals {\n    void init(@TemplateGlobal String user) { } // parameter target\n}\n\n// after\nclass Globals {\n    @TemplateGlobal\n    static String user() { return currentUser(); }\n}","handlingStrategy":"validation","validationCode":"// @TemplateGlobal is valid on class, field, or supported static method only\nif (!(element instanceof Class || element instanceof Field\n      || (element instanceof Method m && Modifier.isStatic(m.getModifiers())))) {\n    throw new IllegalArgumentException(\"Unsupported @TemplateGlobal target\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use @TemplateGlobal as a qualifier or on parameters/constructors","Define globals as public static fields or static methods in a dedicated class","Review Qute @TemplateGlobal docs for the supported element kinds"],"tags":["quarkus","qute","annotation-target","template-global"],"backgroundTag":"invalid-annotation-target","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"}