quarkusio/quarkus · error · IOException

Failed to read model

Error message

Failed to read model

What it means

MojoUtils.readPom(File) wraps any non-IO runtime failure from Maven.readModel into an IOException with message 'Failed to read model'. It indicates the pom.xml could not be parsed into a Maven Model (malformed XML, unreadable file, unsupported model).

Source

Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java:173

     * @param dependencies The plugin extensions
     * @return The plugin instance
     */
    public static Plugin plugin(String groupId, String artifactId, String version, List<Dependency> dependencies) {
        Plugin plugin = new Plugin();
        plugin.setArtifactId(artifactId);
        plugin.setGroupId(groupId);
        plugin.setVersion(version);
        plugin.setDependencies(dependencies);
        return plugin;
    }

    public static Model readPom(final File pom) throws IOException {
        try {
            return Maven.readModel(pom.toPath());
        } catch (UncheckedIOException e) {
            throw e.getCause();
        } catch (RuntimeException e) {
            throw new IOException("Failed to read model", e.getCause());
        }
    }

    public static Model readPom(final InputStream resourceAsStream) throws IOException {
        try (InputStream is = resourceAsStream) {
            return Maven.readModel(is);
        } catch (UncheckedIOException e) {
            throw e.getCause();
        } catch (RuntimeException e) {
            throw new IOException("Failed to read model", e.getCause());
        }
    }

    public static String[] readGavFromPom(final InputStream resourceAsStream) throws IOException {
        Model model = readPom(resourceAsStream);
        return new String[] { model.getGroupId(), model.getArtifactId(), model.getVersion() };
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Verify the file path points to an existing pom.xml
  2. Validate the XML is well-formed (open in an editor or run mvn help:effective-pom)
  3. Check file read permissions for the process user
  4. Inspect the chained cause (getCause) for the underlying parse error

Example fix

// before
Model m = MojoUtils.readPom(new File("src/pom.xml")); // wrong path
// after
File pom = new File("pom.xml");
if (!pom.isFile()) throw new IllegalStateException("pom.xml missing");
Model m = MojoUtils.readPom(pom);
Defensive patterns

Strategy: validation

Validate before calling

if (pom == null || !pom.isFile() || !pom.canRead()) {
    throw new IllegalStateException("pom.xml missing or unreadable: " + pom);
}

Try / catch

try {
    Model m = MojoUtils.readPom(pomFile);
} catch (IOException e) {
    throw new UncheckedIOException("Cannot parse " + pomFile + ": check XML validity", e);
}

Prevention

When it happens

Trigger: Calling MojoUtils.readPom(File) on a file that is missing, unreadable, or not a well-formed pom.xml; Maven.readModel throws a RuntimeException whose cause is chained.

Common situations: Corrupted or hand-edited pom.xml with invalid XML, wrong file path passed in, encoding problems (invalid bytes for declared charset), or a truncated file.

Related errors


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