Skip to content

NPE crash on malformed supplemental-model entry instead of clean error #266

Description

@elharo

Summary

getSupplement(Xpp3Dom) swallows XML parse errors and returns a null Model, and the caller then dereferences it unconditionally → NullPointerException instead of a clean error message.

src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:1008-1033

protected Model getSupplement(Xpp3Dom supplementModelXml) throws MojoExecutionException {
    ...
    try {
        model = modelReader.read(new StringReader(supplementModelXml.toString()));
        ...
    } catch (IOException e) {
        getLog().warn("Unable to read supplemental XML: " + e.getMessage(), e);
    } catch (XmlPullParserException e) {
        getLog().warn("Unable to parse supplemental XML: " + e.getMessage(), e);
    }
    return model;   // null when the inner <project> element is malformed
}

loadSupplements() then calls:

Model m = getSupplement(dom);
supplementMap.put(generateSupplementMapKey(m.getGroupId(), m.getArtifactId()), m);   // NPE if m == null

src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:1082-1083

Impact

A malformed <project> entry inside supplemental-models.xml (e.g. an invalid model element that MavenXpp3Reader rejects) crashes the build with an unhelpful NullPointerException rather than the intended warning/error path. Note the outer wrapper XML is parsed by SupplementalDataModelXpp3Reader in loadSupplements() and fails there cleanly; only the inner <project> DOM→Model conversion hits this path.

Suggested fix

throw a MojoExecutionException on parse failure instead of returning null.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions