{"record":{"id":"71cc4c39a67e9ec5","repo":"quarkusio/quarkus","slug":"invalid-annotation-target-for-templatecontents","errorCode":null,"errorMessage":"Invalid annotation target for @TemplateContents: <target>","messagePattern":"Invalid annotation target for @TemplateContents: <target>","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":2701,"sourceCode":"            } else if (annotation.target().kind() == Kind.METHOD) {\n                MethodInfo method = annotation.target().asMethod();\n                if (Modifier.isStatic(method.flags())\n                        && Modifier.isNative(method.flags())\n                        && method.declaringClass().hasAnnotation(Names.CHECKED_TEMPLATE)) {\n                    AnnotationInstance checkedTemplateAnnotation = method.declaringClass()\n                            .declaredAnnotation(Names.CHECKED_TEMPLATE);\n                    String fragmentId = getCheckedFragmentId(method, checkedTemplateAnnotation);\n                    templatePaths.produce(TemplatePathBuildItem.builder()\n                            .content(annotation.value().asString())\n                            .path(getCheckedTemplatePath(index.getIndex(), checkedTemplateAnnotation, fragmentId,\n                                    method.declaringClass(), method) + suffix)\n                            .extensionInfo(method.toString())\n                            .source(JandexElementUriBuilder.getSource(method, TemplateContents.class))\n                            .build());\n                    continue;\n                }\n            }\n            throw new TemplateException(\"Invalid annotation target for @TemplateContents: \" + annotation.target());\n        }\n    }\n\n    @BuildStep\n    @Record(value = STATIC_INIT)\n    void initialize(BuildProducer<SyntheticBeanBuildItem> syntheticBeans, QuteConfig config, QuteRecorder recorder,\n            EffectiveTemplatePathsBuildItem effectiveTemplatePaths, Optional<TemplateVariantsBuildItem> templateVariants,\n            TemplateRootsBuildItem templateRoots, List<TemplatePathExcludeBuildItem> templatePathExcludes) {\n\n        Map<String, TemplateInfo> templates = new HashMap<>();\n        for (TemplatePathBuildItem template : effectiveTemplatePaths.getTemplatePaths()) {\n            templates.put(template.getPath(),\n                    new TemplateInfo(template.getPath(),\n                            template.getSource() != null ? template.getSource().toString() : null,\n                            template.isFileBased() ? null : template.getContent()));\n        }\n        Map<String, List<String>> variants;\n        if (templateVariants.isPresent()) {","sourceCodeStart":2683,"sourceCodeEnd":2719,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java#L2683-L2719","documentation":"Thrown when @TemplateContents is placed on an annotation target Qute does not support. @TemplateContents is only valid on supported elements (e.g. fields of type Template or classes used with type-safe templates); any other target fails the build.","triggerScenarios":"Applying @TemplateContents to a method, parameter, package, or other element via an inappropriate @Target use; writing a meta-annotation or custom annotation whose target Qute's processor does not handle in its switch over annotation targets.","commonSituations":"Refactoring where @TemplateContents moved from a field to a getter method; experimenting with inline template content on unsupported constructs; IDE quick-fix applying the annotation to the wrong element.","solutions":["Move @TemplateContents onto a supported target (e.g. a field of type Template or a checked template class)","Provide the content via the annotation's value on the supported element instead","Remove the annotation if inline content is not needed and use a template file","Check the @TemplateContents @Target meta-annotation and the Qute version for supported placements"],"exampleFix":"// before\nclass Pages {\n    Template hello() { ... } // method target\n}\n\n// after\nclass Pages {\n    @TemplateContents(\"Hello {name}!\")\n    Template hello;\n}","handlingStrategy":"validation","validationCode":"// Only apply @TemplateContents on supported targets (field of type Template, checked template class)\nif (!(element instanceof Field f) || !Template.class.equals(f.getType())) {\n    throw new IllegalArgumentException(\"@TemplateContents must be on a Template field\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the @Target meta-annotation of @TemplateContents before applying it","Apply the annotation to Template-typed fields only","Prefer @Location references to template files over inline content when unsure"],"tags":["quarkus","qute","annotation-target","template-contents"],"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"}