{"record":{"id":"c4a408b46d9b901e","repo":"quarkusio/quarkus","slug":"failed-to-locate-element-name","errorCode":null,"errorMessage":"Failed to locate element <name>","messagePattern":"Failed to locate element <name>","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"devtools/maven/src/main/java/io/quarkus/maven/CreateUtils.java","lineNumber":94,"sourceCode":"    private static String getChildElementTextValue(final Node parentNode, String childName) throws MojoExecutionException {\n        final Node node = getElement(parentNode.getChildNodes(), childName);\n        final String text = getText(node);\n        if (text.isEmpty()) {\n            throw new MojoExecutionException(\n                    \"The \" + parentNode.getNodeName() + \" element description is missing child \" + childName);\n        }\n        return text;\n    }\n\n    private static Node getElement(NodeList nodeList, String name) throws MojoExecutionException {\n        for (int i = 0; i < nodeList.getLength(); ++i) {\n            final Node item = nodeList.item(i);\n            if (item.getNodeType() == Node.ELEMENT_NODE\n                    && (name.equals(item.getNodeName()) || name.equals(item.getLocalName()))) {\n                return item;\n            }\n        }\n        throw new MojoExecutionException(\"Failed to locate element \" + name);\n    }\n\n    private static String getText(Node node) {\n        if (!node.hasChildNodes()) {\n            return \"\";\n        }\n        StringBuffer result = new StringBuffer();\n        NodeList list = node.getChildNodes();\n        for (int i = 0; i < list.getLength(); i++) {\n            Node subnode = list.item(i);\n            if (subnode.getNodeType() == Node.TEXT_NODE) {\n                result.append(subnode.getNodeValue());\n            } else if (subnode.getNodeType() == Node.CDATA_SECTION_NODE) {\n                result.append(subnode.getNodeValue());\n            } else if (subnode.getNodeType() == Node.ENTITY_REFERENCE_NODE) {\n                // Recurse into the subtree for text\n                // (and ignore comments)\n                result.append(getText(subnode));","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/devtools/maven/src/main/java/io/quarkus/maven/CreateUtils.java#L76-L112","documentation":"CreateUtils.getElement scans a NodeList for an element matching the given local/node name. If no matching ELEMENT_NODE is found after iterating all children, it throws a MojoExecutionException 'Failed to locate element <name>'. It is a strict lookup: the caller (e.g. pluginNode, node) expects a structurally required element.","triggerScenarios":"Calling a Quarkus Maven create-style goal whose resolvePluginInfo path invokes getElement (directly or via getChildElementTextValue/pluginNode) on an XML document that lacks the required element entirely.","commonSituations":"pom.xml or plugin descriptor missing an expected element after manual edits or an upgrade; wrong namespace so getLocalName() does not match; typos in element names; XML malformed or an entirely different document passed for parsing.","solutions":["Add the missing element with the exact expected name to the XML document","Check for namespace issues — the element must match getNodeName() or getLocalName()","Validate the document structure against a known-good working example (e.g. from a freshly generated project)"],"exampleFix":"// before\n<pluginInfo>\n  <!-- <description> missing -->\n</pluginInfo>\n// after\n<pluginInfo>\n  <description>My plugin description</description>\n</pluginInfo>","handlingStrategy":"validation","validationCode":"// Check required elements exist before running the goal\nvar doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(pomFile);\nvar required = java.util.List.of(\"expectedElementName\");\nfor (String name : required) {\n    if (doc.getElementsByTagName(name).getLength() == 0) {\n        throw new IllegalStateException(\"Missing required element <\" + name + \">\");\n    }\n}","typeGuard":"static boolean containsElement(Node parent, String name) {\n    var nodes = parent.getChildNodes();\n    for (int i = 0; i < nodes.getLength(); i++) {\n        Node n = nodes.item(i);\n        if (n.getNodeType() == Node.ELEMENT_NODE\n                && (name.equals(n.getNodeName()) || name.equals(n.getLocalName()))) {\n            return true;\n        }\n    }\n    return false;\n}","tryCatchPattern":"try {\n    mojo.execute();\n} catch (MojoExecutionException e) {\n    if (e.getMessage().startsWith(\"Failed to locate element\")) {\n        String element = e.getMessage().substring(e.getMessage().lastIndexOf(' ') + 1);\n        // add the missing element <element> to the document and re-run\n    }\n}","preventionTips":["Keep project descriptors structurally identical to freshly generated reference projects","Verify XML namespaces when documents use namespace-qualified elements","Diff your descriptor against a working one after upgrades or migrations"],"tags":["maven","xml-parsing","build"],"backgroundTag":"missing-xml-element","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"}