Skip to content

Commit f2135c1

Browse files
authored
[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
1 parent ba2ff7e commit f2135c1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ private PluginInfo extractPluginInfo(Artifact artifact) {
132132
// - maven-plugin-api (for model)
133133
// - Plexus Container (for model supporting classes and exceptions)
134134
Xpp3Dom root = Xpp3DomBuilder.build(reader);
135-
String groupId = root.getChild("groupId").getValue();
136-
String artifactId = root.getChild("artifactId").getValue();
137-
String goalPrefix = root.getChild("goalPrefix").getValue();
138-
String name = root.getChild("name").getValue();
135+
String groupId = mayGetChild(root, "groupId");
136+
String artifactId = mayGetChild(root, "artifactId");
137+
String goalPrefix = mayGetChild(root, "goalPrefix");
138+
String name = mayGetChild(root, "name");
139139
// sanity check: plugin descriptor extracted from artifact must have same GA
140140
if (Objects.equals(artifact.getGroupId(), groupId)
141141
&& Objects.equals(artifact.getArtifactId(), artifactId)) {
142+
// here groupId and artifactId cannot be null
142143
return new PluginInfo(groupId, artifactId, goalPrefix, name);
143144
} else {
144145
throw new InvalidArtifactPluginMetadataException(
@@ -151,16 +152,25 @@ private PluginInfo extractPluginInfo(Artifact artifact) {
151152
}
152153
}
153154
}
154-
} catch (RuntimeException e) {
155-
throw e;
156155
} catch (Exception e) {
156+
if (e instanceof InvalidArtifactPluginMetadataException) {
157+
throw (InvalidArtifactPluginMetadataException) e;
158+
}
157159
// here we can have: IO. ZIP or Plexus Conf Ex: but we should not interfere with user intent
158160
}
159161
}
160162
}
161163
return null;
162164
}
163165

166+
private static String mayGetChild(Xpp3Dom node, String child) {
167+
Xpp3Dom c = node.getChild(child);
168+
if (c != null) {
169+
return c.getValue();
170+
}
171+
return null;
172+
}
173+
164174
public static final class InvalidArtifactPluginMetadataException extends IllegalArgumentException {
165175
InvalidArtifactPluginMetadataException(String s) {
166176
super(s);

0 commit comments

Comments
 (0)