{"record":{"id":"a59bc0ed352993f6","repo":"quarkusio/quarkus","slug":"template-extension-method-parameter-annotated-with","errorCode":null,"errorMessage":"Template extension method parameter annotated with @TemplateAttribute declared on  must be of type java.lang.Object: ","messagePattern":"Template extension method parameter annotated with @TemplateAttribute declared on  must be of type java\\.lang\\.Object: ","errorType":"exception","errorClass":"TemplateException","httpStatus":null,"severity":"error","filePath":"independent-projects/qute/generator/src/main/java/io/quarkus/qute/generator/ExtensionMethodGenerator.java","lineNumber":1000,"sourceCode":"            this.params = params;\n\n            if (isNameParameterRequired) {\n                Param nameParam = getFirst(ParamKind.NAME);\n                if (nameParam == null || !nameParam.type.name().equals(DotNames.STRING)) {\n                    throw new TemplateException(\n                            \"Template extension method declared on \" + method.declaringClass().name()\n                                    + \" must accept at least one string parameter to match the name: \" + method);\n                }\n            }\n            if (!hasNamespace && getFirst(ParamKind.BASE) == null) {\n                throw new TemplateException(\n                        \"Template extension method declared on \" + method.declaringClass().name()\n                                + \" must accept at least one parameter to match the base object: \" + method);\n            }\n\n            for (Param param : params) {\n                if (param.kind == ParamKind.ATTR && !param.type.name().equals(DotNames.OBJECT)) {\n                    throw new TemplateException(\n                            \"Template extension method parameter annotated with @TemplateAttribute declared on \"\n                                    + method.declaringClass().name()\n                                    + \" must be of type java.lang.Object: \" + method);\n                }\n            }\n        }\n\n        public List<Type> parameterTypes() {\n            return params.stream().map(p -> p.type).toList();\n        }\n\n        public String[] parameterTypesAsStringArray() {\n            String[] types = new String[params.size()];\n            for (int i = 0; i < params.size(); i++) {\n                types[i] = params.get(i).type.name().toString();\n            }\n            return types;\n        }","sourceCodeStart":982,"sourceCodeEnd":1018,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/qute/generator/src/main/java/io/quarkus/qute/generator/ExtensionMethodGenerator.java#L982-L1018","documentation":"@TemplateAttribute parameters receive arbitrary attribute values from the template evaluation context, so they must be declared as java.lang.Object. A narrower declared type causes this TemplateException because the generated code cannot safely cast/assign the value.","triggerScenarios":"Annotating a parameter of type String/Integer/etc. with @TemplateAttribute on a template extension method; caught in the generator constructor's param loop.","commonSituations":"Copy-pasting a @RequestAttribute/@TemplateAttribute pattern onto a typed parameter; trying to get type safety by narrowing the attribute parameter type.","solutions":["Change the parameter type to java.lang.Object and cast inside the method body","Remove @TemplateAttribute if the parameter should be a regular extension argument"],"exampleFix":"// before\n@TemplateAttribute String locale\n// after\n@TemplateAttribute Object locale\n// then inside: String loc = (String) locale;","handlingStrategy":"validation","validationCode":"for (var p : m.getParameters())\n    if (p.isAnnotationPresent(TemplateAttribute.class) && p.getType() != Object.class)\n        throw new IllegalStateException(\"@TemplateAttribute param must be Object: \" + p);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always declare @TemplateAttribute params as Object and cast inside","Keep a shared utility for safe attribute extraction","Add signature tests for extension methods using attributes"],"tags":["qute","template-extension","type-safety","build-time"],"backgroundTag":"template-extension-signature-mismatch","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}