Skip to content

Potential NPE in PropertiesMojo when artifact.getFile() returns null #1647

Description

@elharo

PropertiesMojo.execute() at line 114-118:

for (Artifact artifact : artifacts) {
    project.getProperties()
            .setProperty(
                    artifact.getDependencyConflictId(),
                    artifact.getFile().getAbsolutePath());  // NPE if null
}

project.getArtifacts() can include artifacts where getFile() returns null (e.g., unresolved optional dependencies, artifacts with resolution failures that don't fully fail the build). Calling .getAbsolutePath() on null throws NPE and fails the build.

The extra artifact resolution at lines 129-136 has a similar issue:

artifact = resolverUtil.resolveArtifact(artifact, project.getRemoteProjectRepositories());
this.project.getProperties().setProperty(toConflictId(artifact), artifact.getFile().getAbsolutePath());

If resolution succeeds but returns a null file, this also NPEs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions