From 4ff90d2d6a63c5ddbf2c162620d3eff1001f3edc Mon Sep 17 00:00:00 2001 From: per Date: Thu, 6 Nov 2025 20:11:12 +0100 Subject: [PATCH 1/2] add bug reproduced test --- .../resolver/internal/ant/DeployTest.java | 31 +++++++++++++++++++ src/test/resources/ant/Deploy/ant.xml | 22 +++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java index aa7ba04..f5f5cd9 100644 --- a/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java +++ b/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java @@ -22,6 +22,7 @@ import java.util.Arrays; import junit.framework.JUnit4TestAdapter; +import org.apache.tools.ant.BuildException; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,6 +31,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasItemInArray; import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.junit.Assert.fail; /* * still missing: @@ -96,4 +98,33 @@ private void assertUpdatedFile(long min, long max, File repoPath, String path) { file.lastModified(), allOf(greaterThanOrEqualTo(min), lessThanOrEqualTo(max))); } + + /** + * Reproduces an NPE when a deploy <artifact> contains only a nested <pom/>. + *
{@code
+     *   
+     *     
+     *       
+     *     
+     *     
+     *   
+     * }
+ * Current behavior: Ant build fails with a NullPointerException at the root cause. + * Once the deploy task supports this case or throws a clearer error, update the assertion accordingly. + */ + @Test + public void testDeployOnlyNestedPomCausesNpe() { + try { + executeTarget("testDeployOnlyNestedPomCausesNpe"); + fail("Expected the build to fail when deploying with only a nested inside ."); + } catch (BuildException e) { + Throwable cause = e; + while (cause.getCause() != null) { + cause = cause.getCause(); + } + if (!(cause instanceof NullPointerException)) { + fail("Expected NullPointerException as root cause, but was: " + cause); + } + } + } } diff --git a/src/test/resources/ant/Deploy/ant.xml b/src/test/resources/ant/Deploy/ant.xml index 2ad2d7a..3588378 100644 --- a/src/test/resources/ant/Deploy/ant.xml +++ b/src/test/resources/ant/Deploy/ant.xml @@ -69,4 +69,26 @@ + + + + + + + This is a test artifact content. + + + + + + + + + + + + From c9dacb3672fccfba1109eac6e1287e376b26e4d4 Mon Sep 17 00:00:00 2001 From: per Date: Fri, 7 Nov 2025 16:05:29 +0100 Subject: [PATCH 2/2] defensive fix, don't allow only a nested pom declaration without a registered pom present. --- .../resolver/internal/ant/tasks/AbstractDistTask.java | 9 +++++++-- .../apache/maven/resolver/internal/ant/DeployTest.java | 8 ++++---- src/test/resources/ant/Deploy/ant.xml | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/maven/resolver/internal/ant/tasks/AbstractDistTask.java b/src/main/java/org/apache/maven/resolver/internal/ant/tasks/AbstractDistTask.java index 84dec13..f7e1c31 100644 --- a/src/main/java/org/apache/maven/resolver/internal/ant/tasks/AbstractDistTask.java +++ b/src/main/java/org/apache/maven/resolver/internal/ant/tasks/AbstractDistTask.java @@ -130,13 +130,18 @@ private void validateArtifactGav(final Artifact artifact) { version = artifactPom.getVersion(); } - final Model model = getPom().getModel(this); + final Pom pom = getPom(); + if (pom == null) { + throw new BuildException("You must specify the element" + + " to denote the descriptor for the artifacts"); + } + final Model model = pom.getModel(this); if (!(model.getGroupId().equals(gid) && model.getArtifactId().equals(aid) && model.getVersion().equals(version))) { throw new BuildException( - "Artifact references different pom than it would be installed with: " + artifact.toString()); + "Artifact references different pom than it would be installed with: " + artifact); } } } diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java index f5f5cd9..74b38ef 100644 --- a/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java +++ b/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java @@ -113,16 +113,16 @@ private void assertUpdatedFile(long min, long max, File repoPath, String path) { * Once the deploy task supports this case or throws a clearer error, update the assertion accordingly. */ @Test - public void testDeployOnlyNestedPomCausesNpe() { + public void testDeployOnlyNestedPomException() { try { - executeTarget("testDeployOnlyNestedPomCausesNpe"); + executeTarget("testDeployOnlyNestedPomException"); fail("Expected the build to fail when deploying with only a nested inside ."); - } catch (BuildException e) { + } catch (Exception e) { Throwable cause = e; while (cause.getCause() != null) { cause = cause.getCause(); } - if (!(cause instanceof NullPointerException)) { + if (!(cause instanceof BuildException)) { fail("Expected NullPointerException as root cause, but was: " + cause); } } diff --git a/src/test/resources/ant/Deploy/ant.xml b/src/test/resources/ant/Deploy/ant.xml index 3588378..289d3a3 100644 --- a/src/test/resources/ant/Deploy/ant.xml +++ b/src/test/resources/ant/Deploy/ant.xml @@ -70,10 +70,10 @@ - +