apache/maven · error · XmlPullParserException

Expected root element 'extensions' but found no element at a

Error message

Expected root element 'extensions' but found no element at all: invalid XML document

What it means

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.

Source

Thrown at compat/maven-embedder/src/main/java/org/apache/maven/cli/internal/extension/model/io/xpp3/CoreExtensionsXpp3Reader.java:527

        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                if (strict && !"extensions".equals(parser.getName())) {
                    throw new XmlPullParserException(
                            "Expected root element 'extensions' but found '" + parser.getName() + "'", parser, null);
                } else if (parsed) {
                    // fallback, already expected a XmlPullParserException due to invalid XML
                    throw new XmlPullParserException("Duplicated tag: 'extensions'", parser, null);
                }
                coreExtensions = parseCoreExtensions(parser, strict);
                coreExtensions.setModelEncoding(parser.getInputEncoding());
                parsed = true;
            }
            eventType = parser.next();
        }
        if (parsed) {
            return coreExtensions;
        }
        throw new XmlPullParserException(
                "Expected root element 'extensions' but found no element at all: invalid XML document", parser, null);
    } // -- CoreExtensions read( XmlPullParser, boolean )

    /**
     * @see XmlStreamReader
     *
     * @param reader a reader object.
     * @param strict a strict object.
     * @throws IOException IOException if any.
     * @throws XmlPullParserException XmlPullParserException if
     * any.
     * @return CoreExtensions
     */
    public CoreExtensions read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
        XmlPullParser parser =
                addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();

        parser.setInput(reader);

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Inspect the file: ls -l .mvn/extensions.xml — a 0-byte or prolog-only file is the cause.
  2. Write a minimal valid document: <extensions xmlns="http://maven.apache.org/EXTENSIONS/1.2.0"></extensions> (or with your extension entries).
  3. Delete the file if no core extensions are needed — absence of the file is fine; an empty one is not.
  4. Fix the generator to write the full document atomically and fail loudly on write errors.

Example fix

# before: empty file
touch .mvn/extensions.xml

# after: valid minimal document
printf '<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.2.0"></extensions>\n' > .mvn/extensions.xml
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: file must contain a root element
Path p = Path.of(".mvn/extensions.xml");
if (Files.exists(p)) {
    String content = Files.readString(p).trim();
    if (!content.startsWith("<")) {
        throw new IllegalStateException("extensions.xml exists but has no XML element: " + p);
    }
}

Try / catch

try {
    cli.doMain(args, workingDir, ...);
} catch (org.codehaus.plexus.util.xml.pull.XmlPullParserException e) {
    if (e.getMessage() != null && e.getMessage().contains("found no element at all")) {
        // write a minimal <extensions></extensions> or delete the file, then retry
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/64ce59a7d375dcc6. Report an issue: GitHub.