This is an automated email from the ASF dual-hosted git repository. cstamas pushed a commit to branch maven-3.9.x in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.9.x by this push: new f2135c1863 [MNG-8180] Handle NPE due non-existent tags (#1641) f2135c1863 is described below commit f2135c186397993e3bba7025607c21f27b58a047 Author: Tamas Cservenak <ta...@cservenak.net> AuthorDate: Sun Aug 11 18:56:21 2024 +0200 [MNG-8180] Handle NPE due non-existent tags (#1641) There was an NPE possibility when plugin.xml had no expected tags present. Also: maven-compat has plugin.xml (!) w/o "name" tag, it NPEd and failed build. This was NOT picked up by CI as "rebuild itself" step does not install (just verify). --- https://issues.apache.org/jira/browse/MNG-8180 --- .../internal/PluginsMetadataGenerator.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java index b37992df30..3803572f6d 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java @@ -132,13 +132,14 @@ class PluginsMetadataGenerator implements MetadataGenerator { // - maven-plugin-api (for model) // - Plexus Container (for model supporting classes and exceptions) Xpp3Dom root = Xpp3DomBuilder.build(reader); - String groupId = root.getChild("groupId").getValue(); - String artifactId = root.getChild("artifactId").getValue(); - String goalPrefix = root.getChild("goalPrefix").getValue(); - String name = root.getChild("name").getValue(); + String groupId = mayGetChild(root, "groupId"); + String artifactId = mayGetChild(root, "artifactId"); + String goalPrefix = mayGetChild(root, "goalPrefix"); + String name = mayGetChild(root, "name"); // sanity check: plugin descriptor extracted from artifact must have same GA if (Objects.equals(artifact.getGroupId(), groupId) && Objects.equals(artifact.getArtifactId(), artifactId)) { + // here groupId and artifactId cannot be null return new PluginInfo(groupId, artifactId, goalPrefix, name); } else { throw new InvalidArtifactPluginMetadataException( @@ -151,9 +152,10 @@ class PluginsMetadataGenerator implements MetadataGenerator { } } } - } catch (RuntimeException e) { - throw e; } catch (Exception e) { + if (e instanceof InvalidArtifactPluginMetadataException) { + throw (InvalidArtifactPluginMetadataException) e; + } // here we can have: IO. ZIP or Plexus Conf Ex: but we should not interfere with user intent } } @@ -161,6 +163,14 @@ class PluginsMetadataGenerator implements MetadataGenerator { return null; } + private static String mayGetChild(Xpp3Dom node, String child) { + Xpp3Dom c = node.getChild(child); + if (c != null) { + return c.getValue(); + } + return null; + } + public static final class InvalidArtifactPluginMetadataException extends IllegalArgumentException { InvalidArtifactPluginMetadataException(String s) { super(s);