{"record":{"id":"f62986e2ccd4feba","repo":"apache/maven","slug":"expected-root-element-roottag-but-found-no-el-f62986","errorCode":null,"errorMessage":"Expected root element '${rootTag}' but found no element at all: invalid XML document","messagePattern":"Expected root element '(.+?)' but found no element at all: invalid XML document","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader.vm","lineNumber":455,"sourceCode":"        int eventType = parser.getEventType();\n        boolean parsed = false;\n        while (eventType != XMLStreamReader.END_DOCUMENT) {\n            if (eventType == XMLStreamReader.START_ELEMENT) {\n                if (strict && ! \"${rootTag}\".equals(parser.getLocalName())) {\n                    throw new XMLStreamException(\"Expected root element '${rootTag}' but found '\" + parser.getLocalName() + \"'\", parser.getLocation(), null);\n                } else if (parsed) {\n                    // fallback, already expected a XMLStreamException due to invalid XML\n                    throw new XMLStreamException(\"Duplicated tag: '${rootTag}'\", parser.getLocation(), null);\n                }\n                $rootLcapName = parse${rootUcapName}(parser, strict);\n                parsed = true;\n            }\n            eventType = parser.next();\n        }\n        if (parsed) {\n            return $rootLcapName;\n        }\n        throw new XMLStreamException(\"Expected root element '${rootTag}' but found no element at all: invalid XML document\", parser.getLocation(), null);\n    } //-- ${root.name} read(XMLStreamReader, boolean)\n\n#foreach ( $class in $model.allClasses )\n #if ( $class.name != \"InputSource\" && $class.name != \"InputLocation\" )\n  #set ( $classUcapName = $Helper.capitalise( $class.name ) )\n  #set ( $classLcapName = $Helper.uncapitalise( $class.name ) )\n  #set ( $ancestors = $Helper.ancestors( $class ) )\n  #set ( $allFields = [] )\n  #foreach ( $cl in $ancestors )\n    #set ( $dummy = $allFields.addAll( $cl.getFields($version) ) )\n  #end\n    private ${classUcapName} parse${classUcapName}(XMLStreamReader parser, boolean strict)\n            throws IOException, XMLStreamException {\n        String tagName = parser.getLocalName();\n        ${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder(true);\n        for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {\n            String name = parser.getAttributeLocalName(i);\n            String ns = parser.getAttributeNamespace(i);","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader.vm#L437-L473","documentation":"Same empty-document guard as reader-stax.vm: the read loop in read(XMLStreamReader, strict) reached END_DOCUMENT with parsed still false - no START_ELEMENT was ever seen. Empty files, whitespace-only input, or declaration/comment-only documents produce this; the parser location marks the end of the document.","triggerScenarios":"read() on a zero-byte stream; a file with only whitespace or only an <?xml declaration; a stream already consumed by an earlier parse; comments-only content.","commonSituations":"Empty placeholder files; failed generation steps writing empty XML; drained streams reused for a second read.","solutions":["Check input non-emptiness before parsing.","Peek for a root element and reject empties with a file-specific error.","Fix the producer writing empty files; skip optional documents."],"exampleFix":"// before\nModel model = reader.read(new FileInputStream(file), true); // 0-byte file\n\n// after\nif (file.length() == 0) {\n    throw new IllegalArgumentException(file.getPath() + \" is empty\");\n}\nModel model = reader.read(new FileInputStream(file), true);","handlingStrategy":"validation","validationCode":"byte[] bytes = in.readAllBytes();\nif (bytes.length == 0) {\n    throw new IllegalArgumentException(\"empty XML input\");\n}\nModel model = reader.read(new ByteArrayInputStream(bytes), true);","typeGuard":null,"tryCatchPattern":"try {\n    Model model = reader.read(in, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"found no element at all\")) {\n        // empty document: identify and report the source file\n    }\n    throw e;\n}","preventionTips":["Guard parses with a length check.","Buffer streams and detect emptiness cheaply.","Make empty-file writers fail loudly."],"tags":["xml","stax","empty-input","parsing"],"backgroundTag":"empty-xml-document","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}