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

Open Beginner friendly
#1,647 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java
Domain
build-system

Research direction

Start in PropertiesMojo.execute() at the two artifact property-setting paths shown in the issue, including the extra resolution branch. Trace how unresolved or optionally unresolved artifacts can have a null file, then verify that such artifacts no longer trigger an NPE while artifacts with files still produce their absolute paths.

Written by the indexing model from the issue text.

Description

bug

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.

Dominant language
Java
Stars
175
Forks
196
Avg merge
11h 40m
Merged PRs (30d)
11

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/maven-dependency-plugin

All issues in apache/maven-dependency-plugin

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.