You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "elharo (via GitHub)" <gi...@apache.org> on 2026/08/03 18:40:07 UTC
[I] attachartifact throws ClassCastException when mavenProjectRefId points at the plain MavenProject reference [maven-antrun-plugin]
elharo opened a new issue, #375:
URL: https://github.com/apache/maven-antrun-plugin/issues/375
## 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`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org