apache / apache/maven-antrun-plugin

copyProperties throws NPE on dependencies with no resolved artifact file

Open Beginner friendly
#372 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
36
Forks
20
Avg merge
1h 48m
Merged PRs (30d)
1

Description

## 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`)

```java
Set 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`:

```java
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Read src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java around lines 430-436 and compare it with getPathFromArtifacts around lines 362-381. Reproduce the dependency case with a null artifact file, then verify that copyProperties skips it or reports a clear resolution error instead of throwing an opaque NullPointerException.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.