apache / apache/maven-antrun-plugin
attachartifact throws ClassCastException when mavenProjectRefId points at the plain MavenProject reference
- Dominant language
- Java
- Stars
- 36
- Forks
- 20
- Avg merge
- 1h 48m
- Merged PRs (30d)
- 1
Description
## Summary
`AttachArtifactTask` casts the Maven project reference to `MavenAntRunProject` unconditionally. If the `mavenProjectRefId` attribute is set to a reference that holds a plain `MavenProject` (e.g. the `maven.project` reference the antrun mojo registers), the task throws a raw `ClassCastException` instead of a clear `BuildException`.
## Affected code
`src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java` lines 62-72 (master @ `441382c`)
```java
if (this.getProject().getReference(mavenProjectRefId) == null) {
throw new BuildException("Maven project reference not found: " + mavenProjectRefId);
}
String type = configuration.getType();
if (type == null) {
type = FileUtils.getExtension(file.getName());
}
MavenProject mavenProject =
((MavenAntRunProject) this.getProject().getReference(mavenProjectRefId)).getMavenProject();
```
## Problem
The task's default reference (`maven.project.ref`) is a `MavenAntRunProject` wrapper, and the cast at line 71 is only valid for that wrapper. The `mavenProjectRefId` attribute is user-configurable, but any value resolving to a different type — most naturally `maven.project`, the plain `MavenProject` reference that the `AntRunMojo` also registers (AntRunMojo.java:350) — results in a `ClassCastException` with no indication of the real problem.
## Expected behavior
The reference should be handled by type (e.g. check `instanceof` and unwrap `MavenProject` or `MavenAntRunProject` accordingly), or reject an incompatible reference with a clear `BuildException`, rather than crashing with a `ClassCastException`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.