gnodet-bot commented on code in PR #13945:
URL: https://github.com/apache/maven/pull/13945#discussion_r4527130866


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/AetherDependencyWrapper.java:
##########
@@ -116,6 +119,30 @@ public DependencyScope scope() {
         return session.requireDependencyScope(dependency.getScope());
     }
 
+    /**
+     * {@return the transitive dependency exclusions}
+     */
+    @Nonnull
+    public Collection<Exclusion> exclusions() {
+        return new MappedCollection<>(dependency.getExclusions(), 
this::toExclusion);
+    }
+
+    private Exclusion toExclusion(org.eclipse.aether.graph.Exclusion 
exclusion) {
+        return new Exclusion() {
+            @Nullable
+            @Override
+            public String groupId() {
+                return exclusion.getGroupId();
+            }
+
+            @Nullable
+            @Override
+            public String artifactId() {
+                return exclusion.getArtifactId();
+            }
+        };
+    }

Review Comment:
   `toExclusion()` marks `groupId()` and `artifactId()` as `@Nullable`, but the 
`Exclusion` interface declares them as plain `String` with no `@Nullable` 
annotation — the implicit contract is non-null. Any downstream code iterating 
`exclusions()` and using groupId/artifactId as a map key or in string 
formatting will NPE on a null value.
   
   Aether's `Exclusion` uses `"*"` as its wildcard sentinel (not null), so this 
will not fire in practice today — but the annotation creates a contract 
mismatch that will bite future callers. Either:
   
   1. Annotate `Exclusion.groupId()` and `Exclusion.artifactId()` with 
`@Nullable` in the API (broadens the contract intentionally), or
   2. Normalize null to `"*"` here (keeps the API contract tight):
   
   ```suggestion
       private Exclusion toExclusion(org.eclipse.aether.graph.Exclusion 
exclusion) {
           return new Exclusion() {
               @Nonnull
               @Override
               public String groupId() {
                   String g = exclusion.getGroupId();
                   return g != null ? g : "*";
               }
   
               @Nonnull
               @Override
               public String artifactId() {
                   String a = exclusion.getArtifactId();
                   return a != null ? a : "*";
               }
           };
       }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to