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)
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.
Summary
AttachArtifactTaskcasts the Maven project reference toMavenAntRunProjectunconditionally. If themavenProjectRefIdattribute is set to a reference that holds a plainMavenProject(e.g. themaven.projectreference the antrun mojo registers), the task throws a rawClassCastExceptioninstead of a clearBuildException.Affected code
src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.javalines 62-72 (master @441382c)Problem
The task's default reference (
maven.project.ref) is aMavenAntRunProjectwrapper, and the cast at line 71 is only valid for that wrapper. ThemavenProjectRefIdattribute is user-configurable, but any value resolving to a different type — most naturallymaven.project, the plainMavenProjectreference that theAntRunMojoalso registers (AntRunMojo.java:350) — results in aClassCastExceptionwith no indication of the real problem.Expected behavior
The reference should be handled by type (e.g. check
instanceofand unwrapMavenProjectorMavenAntRunProjectaccordingly), or reject an incompatible reference with a clearBuildException, rather than crashing with aClassCastException.