{"record":{"id":"94dde8146f59825c","repo":"mybatis/mybatis-3","slug":"variable-name-defined-twice-in-the-same-include","errorCode":null,"errorMessage":"Variable {name} defined twice in the same include definition","messagePattern":"Variable (.+?) defined twice in the same include definition","errorType":"validation","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/builder/xml/XMLIncludeTransformer.java","lineNumber":132,"sourceCode":"   * @param inheritedVariablesContext\n   *          Current context used for replace variables in new variables values\n   *\n   * @return variables context from include instance (no inherited values)\n   */\n  private Properties getVariablesContext(Node node, Properties inheritedVariablesContext) {\n    Map<String, String> declaredProperties = null;\n    NodeList children = node.getChildNodes();\n    for (int i = 0; i < children.getLength(); i++) {\n      Node n = children.item(i);\n      if (n.getNodeType() == Node.ELEMENT_NODE) {\n        String name = getStringAttribute(n, \"name\");\n        // Replace variables inside\n        String value = PropertyParser.parse(getStringAttribute(n, \"value\"), inheritedVariablesContext);\n        if (declaredProperties == null) {\n          declaredProperties = new HashMap<>();\n        }\n        if (declaredProperties.put(name, value) != null) {\n          throw new BuilderException(\"Variable \" + name + \" defined twice in the same include definition\");\n        }\n      }\n    }\n    if (declaredProperties == null) {\n      return inheritedVariablesContext;\n    }\n    Properties newProperties = new Properties();\n    newProperties.putAll(inheritedVariablesContext);\n    newProperties.putAll(declaredProperties);\n    return newProperties;\n  }\n}\n","sourceCodeStart":114,"sourceCodeEnd":145,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/builder/xml/XMLIncludeTransformer.java#L114-L145","documentation":"Thrown by XMLIncludeTransformer when parsing the <property> children of an <include> element: the same variable name is declared twice within one include definition. Each child element's name/value becomes an entry in the include's variable context, and a duplicate put() is rejected immediately at parse time.","triggerScenarios":"<include refid=\"...\"><property name=\"col\" value=\"a\"/><property name=\"col\" value=\"b\"/></include> — two <property> elements with identical name attributes inside the same <include>.","commonSituations":"Copy-pasting a property line to tweak the value and leaving both copies; refactoring a shared include's parameters; hand-merging mapper XML during conflict resolution keeping both sides' property lines.","solutions":["Remove the duplicate <property> so each name appears exactly once inside the include","If two values are genuinely needed, rename one of the properties and update the ${placeholder} in the referenced <sql> fragment","Grep the mapper for '<property name=\"<dupName>\"' to catch all copies"],"exampleFix":"<!-- before -->\n<include refid=\"cols\">\n  <property name=\"alias\" value=\"u\"/>\n  <property name=\"alias\" value=\"o\"/>\n</include>\n\n<!-- after -->\n<include refid=\"cols\">\n  <property name=\"alias\" value=\"u\"/>\n</include>","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (Element p : includePropertyChildren) {\n  if (!seen.add(p.getAttribute(\"name\")))\n    throw new IllegalStateException(\"duplicate include property: \" + p.getAttribute(\"name\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One <property> per variable per include","Lint duplicate attributes during code review of mapper XML"],"tags":["mybatis","mapper-xml","include","duplicate-property"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}