{"record":{"id":"64ce59a7d375dcc6","repo":"apache/maven","slug":"expected-root-element-extensions-but-found-no-el","errorCode":null,"errorMessage":"Expected root element 'extensions' but found no element at all: invalid XML document","messagePattern":"Expected root element 'extensions' but found no element at all: invalid XML document","errorType":"exception","errorClass":"XmlPullParserException","httpStatus":null,"severity":"error","filePath":"compat/maven-embedder/src/main/java/org/apache/maven/cli/internal/extension/model/io/xpp3/CoreExtensionsXpp3Reader.java","lineNumber":527,"sourceCode":"        while (eventType != XmlPullParser.END_DOCUMENT) {\n            if (eventType == XmlPullParser.START_TAG) {\n                if (strict && !\"extensions\".equals(parser.getName())) {\n                    throw new XmlPullParserException(\n                            \"Expected root element 'extensions' but found '\" + parser.getName() + \"'\", parser, null);\n                } else if (parsed) {\n                    // fallback, already expected a XmlPullParserException due to invalid XML\n                    throw new XmlPullParserException(\"Duplicated tag: 'extensions'\", parser, null);\n                }\n                coreExtensions = parseCoreExtensions(parser, strict);\n                coreExtensions.setModelEncoding(parser.getInputEncoding());\n                parsed = true;\n            }\n            eventType = parser.next();\n        }\n        if (parsed) {\n            return coreExtensions;\n        }\n        throw new XmlPullParserException(\n                \"Expected root element 'extensions' but found no element at all: invalid XML document\", parser, null);\n    } // -- CoreExtensions read( XmlPullParser, boolean )\n\n    /**\n     * @see XmlStreamReader\n     *\n     * @param reader a reader object.\n     * @param strict a strict object.\n     * @throws IOException IOException if any.\n     * @throws XmlPullParserException XmlPullParserException if\n     * any.\n     * @return CoreExtensions\n     */\n    public CoreExtensions read(Reader reader, boolean strict) throws IOException, XmlPullParserException {\n        XmlPullParser parser =\n                addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();\n\n        parser.setInput(reader);","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-embedder/src/main/java/org/apache/maven/cli/internal/extension/model/io/xpp3/CoreExtensionsXpp3Reader.java#L509-L545","documentation":"CoreExtensionsXpp3Reader.read() loops over pull-parser events; if it reaches END_DOCUMENT without ever seeing a START_TAG for the root element, it throws XmlPullParserException 'Expected root element 'extensions' but found no element at all: invalid XML document'. For .mvn/extensions.xml this means the file exists but contains no XML element: it is empty, whitespace-only, or contains only an XML declaration/prolog and comments.","triggerScenarios":"A zero-byte .mvn/extensions.xml created by touch or by a script that opened the file but wrote nothing. A file containing only <?xml version=\"1.0\"?> and comments. A failed templating step that truncated the file to empty.","commonSituations":"CI generating the extensions file conditionally and emitting an empty placeholder. Editors leaving an empty file after a botched refactor. Files where a heredoc write failed silently (disk full, permissions), leaving a 0-byte file.","solutions":["Inspect the file: ls -l .mvn/extensions.xml — a 0-byte or prolog-only file is the cause.","Write a minimal valid document: <extensions xmlns=\"http://maven.apache.org/EXTENSIONS/1.2.0\"></extensions> (or with your extension entries).","Delete the file if no core extensions are needed — absence of the file is fine; an empty one is not.","Fix the generator to write the full document atomically and fail loudly on write errors."],"exampleFix":"# before: empty file\ntouch .mvn/extensions.xml\n\n# after: valid minimal document\nprintf '<extensions xmlns=\"http://maven.apache.org/EXTENSIONS/1.2.0\"></extensions>\\n' > .mvn/extensions.xml","handlingStrategy":"validation","validationCode":"// Pre-flight: file must contain a root element\nPath p = Path.of(\".mvn/extensions.xml\");\nif (Files.exists(p)) {\n    String content = Files.readString(p).trim();\n    if (!content.startsWith(\"<\")) {\n        throw new IllegalStateException(\"extensions.xml exists but has no XML element: \" + p);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    cli.doMain(args, workingDir, ...);\n} catch (org.codehaus.plexus.util.xml.pull.XmlPullParserException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"found no element at all\")) {\n        // write a minimal <extensions></extensions> or delete the file, then retry\n    }\n    throw e;\n}","preventionTips":["Make config generators write-or-delete, never leave an empty file behind.","Assert non-zero size plus a leading '<' for extensions.xml in CI preflight when the file is expected to exist.","Remember: absence of .mvn/extensions.xml is valid and skips core-extension loading entirely."],"tags":["maven","core-extensions","extensions-xml","xml","parse-error","empty-file"],"backgroundTag":"malformed-xml-config","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}