Skip to content

copyProperties throws NPE on dependencies with no resolved artifact file #372

Description

@elharo

Summary

AntRunMojo.copyProperties(MavenProject, Project) dereferences artifact.getFile() without a null check when registering the per-dependency artifact properties. Any project dependency whose artifact has no resolved file crashes the mojo with an opaque NullPointerException instead of a clear resolution error.

Affected code

src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java lines 430-436 (master @ 441382c)

Set<Artifact> depArtifacts = mavenProject.getArtifacts();
for (Artifact artifact : depArtifacts) {
    String propName = artifact.getDependencyConflictId();
    antProject.setProperty(propertyPrefix + propName, artifact.getFile().getPath());
}

Problem

artifact.getFile() may be null (e.g. partial/offline resolution, or dependencies whose artifact file was never downloaded), and the code calls .getPath() on it directly. The same class already handles this case consistently in getPathFromArtifacts (AntRunMojo.java:362-381), which throws a DependencyResolutionRequiredException when artifact.getFile() == null:

for (Artifact a : artifacts) {
    File file = a.getFile();
    if (file == null) {
        throw new DependencyResolutionRequiredException(a);
    }
    list.add(file.getPath());
}

Expected behavior

Dependency artifacts with no resolved file should be skipped or reported with a clear, actionable error (matching getPathFromArtifacts), rather than aborting the whole mojo with an NPE that gives no hint of which dependency is the cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions