{"record":{"id":"7de05b52a07aaa07","repo":"quarkusio/quarkus","slug":"duplicate-global-variable-defined-via-templateglo","errorCode":null,"errorMessage":"Duplicate global variable defined via @TemplateGlobal for the name [%s]:\n\t- %s\n\t- %s","messagePattern":"Duplicate global variable defined via @TemplateGlobal for the name \\[(.+?)\\]:\n\t- (.+?)\n\t- (.+?)","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":3576,"sourceCode":"    }\n\n    private void addGlobalField(AnnotationValue nameValue, FieldInfo field, Map<String, TemplateGlobalBuildItem> nameToGlobal) {\n        TemplateGlobalGenerator.validate(field);\n        String name = TemplateGlobal.ELEMENT_NAME;\n        if (nameValue != null) {\n            name = nameValue.asString();\n        }\n        if (name.equals(TemplateGlobal.ELEMENT_NAME)) {\n            name = field.name();\n        }\n        TemplateGlobalBuildItem global = new TemplateGlobalBuildItem(name, field, field.type());\n        addGlobalVariable(global, nameToGlobal);\n    }\n\n    private void addGlobalVariable(TemplateGlobalBuildItem global, Map<String, TemplateGlobalBuildItem> nameToGlobal) {\n        TemplateGlobalBuildItem prev = nameToGlobal.put(global.getName(), global);\n        if (prev != null) {\n            throw new TemplateException(\n                    String.format(\"Duplicate global variable defined via @TemplateGlobal for the name [%s]:\\n\\t- %s\\n\\t- %s\",\n                            global.getName(), global, prev));\n        }\n    }\n\n    @BuildStep\n    void collectTemplateDataAnnotations(BeanArchiveIndexBuildItem beanArchiveIndex,\n            BuildProducer<TemplateDataBuildItem> templateDataAnnotations) {\n        IndexView index = beanArchiveIndex.getIndex();\n        Set<AnnotationInstance> annotationInstances = new HashSet<>();\n        annotationInstances.addAll(index.getAnnotations(ValueResolverGenerator.TEMPLATE_DATA));\n        for (AnnotationInstance containingInstance : index.getAnnotations(ValueResolverGenerator.TEMPLATE_DATA_CONTAINER)) {\n            for (AnnotationInstance nestedInstance : containingInstance.value().asNestedArray()) {\n                // We need to use the target of the containing instance\n                annotationInstances.add(\n                        AnnotationInstance.create(nestedInstance.name(), containingInstance.target(), nestedInstance.values()));\n            }\n        }","sourceCodeStart":3558,"sourceCodeEnd":3594,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java#L3558-L3594","documentation":"Thrown when two @TemplateGlobal elements produce a global variable with the same name. Qute registers globals in a name-keyed map and fails the build on collision so that template {name} resolution is unambiguous.","triggerScenarios":"Two fields or static methods annotated with @TemplateGlobal producing the same variable name; a @TemplateGlobal class with auto-generated members whose name collides with another explicit global; two dependencies both defining a global with the same key.","commonSituations":"Common names like 'user', 'now', or 'version' defined in multiple global classes; merging branches that each added a global with the same name; copy-pasting a global method and not renaming it.","solutions":["Rename one of the colliding globals so each name is unique","Remove the duplicate definition if redundant","Consolidate both definitions into a single @TemplateGlobal class/field","If the collision comes from a library, define your own uniquely-named global instead"],"exampleFix":"// before\n@TemplateGlobal static String user() {...}  // in A\n@TemplateGlobal static String user() {...}  // in B\n\n// after\n@TemplateGlobal static String user() {...}      // in A\n@TemplateGlobal static String currentUser() {...} // renamed in B","handlingStrategy":"validation","validationCode":"// Ensure global names are unique across all @TemplateGlobal classes\nSet<String> seen = new HashSet<>();\nfor (String name : allGlobalNames) {\n    if (!seen.add(name)) { throw new IllegalStateException(\"Duplicate global: \" + name); }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize globals in one @TemplateGlobal class","Prefix global names with a domain (e.g. currentUser, appVersion)","Grep for @TemplateGlobal before adding a new global name"],"tags":["quarkus","qute","duplicate-definition","template-global"],"backgroundTag":"duplicate-definition-collision","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"}