quarkusio/quarkus · error · IOException

Failed to parse POM

Error message

Failed to parse POM

What it means

ModelUtils.readModel(InputStream) parses a POM with MavenXpp3Reader. If the stream is not well-formed XML (XmlPullParserException), it is rethrown as IOException("Failed to parse POM", e). It means the pom.xml content itself is malformed, not that the file is missing.

Solutions

  1. Open the pom.xml at the reported path and fix the XML syntax; run `mvn validate` or `xmllint --noout pom.xml` to confirm it parses.
  2. If merge conflict markers are present, resolve the merge and commit a clean pom.xml.
  3. Restore a corrupted/truncated pom.xml (git checkout -- pom.xml or rebuild it).
  4. Ensure the correct file path is being passed to readModel.

Example fix

// before: conflicted pom.xml
<<<<<<< HEAD
  <version>1.0.0</version>
=======
  <version>2.0.0</version>
>>>>>>> feature
// after: resolved
  <version>2.0.0</version>
Defensive patterns

Strategy: validation

Validate before calling

static void validatePomXml(Path pom) throws IOException {
    try {
        new javax.xml.parsers.DocumentBuilderFactory().newInstance()
            .newDocumentBuilder().parse(pom.toFile());
    } catch (Exception e) {
        throw new IOException("Malformed POM XML: " + pom + " - " + e.getMessage(), e);
    }
}

Try / catch

try {
    Model model = ModelUtils.readModel(pomStream);
} catch (IOException e) {
    if (e.getCause() instanceof XmlPullParserException) {
        throw new IllegalStateException("Fix XML syntax in the POM: " + e.getCause().getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling ModelUtils.readModel(Path) or readModel(InputStream) on a pom.xml containing XML syntax errors: unclosed tags, invalid characters/encoding, garbage bytes, truncated file, HTML instead of XML, or reading a non-XML file path by mistake.

Common situations: A merge conflict left conflict markers (<<<<<<<) in pom.xml; an interrupted build/write truncated the file; manual edits broke a tag; wrong file passed (e.g. a .txt or log file); encoding mismatches (BOM, non-UTF-8 bytes).

Understand the failure class

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/ace9837dddce34d1. Report an issue: GitHub.

Appendix: source

Thrown at independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ModelUtils.java:261

        }
        final Properties props = new Properties();
        try (BufferedReader reader = Files.newBufferedReader(propsPath)) {
            props.load(reader);
        }
        return props;
    }

    public static Model readModel(final Path pomXml) throws IOException {
        Model model = readModel(Files.newInputStream(pomXml));
        model.setPomFile(pomXml.toFile());
        return model;
    }

    public static Model readModel(InputStream stream) throws IOException {
        try (InputStream is = stream) {
            return new MavenXpp3Reader().read(is);
        } catch (XmlPullParserException e) {
            throw new IOException("Failed to parse POM", e);
        }
    }

    public static void persistModel(Path pomFile, Model model) throws IOException {
        final MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
        try (BufferedWriter pomFileWriter = Files.newBufferedWriter(pomFile)) {
            xpp3Writer.write(pomFileWriter, model);
        }
    }
}

View on GitHub (pinned to e1c734241f)