elharo commented on code in PR #2037:
URL: https://github.com/apache/maven/pull/2037#discussion_r1912014544


##########
api/maven-api-core/src/main/java/org/apache/maven/api/services/BaseRequest.java:
##########
@@ -52,9 +51,16 @@ public static <T> T nonNull(T obj, String message) {
         return obj;
     }
 
-    protected static <T> Collection<T> unmodifiable(Collection<T> obj) {
-        return obj != null && !obj.isEmpty()
-                ? Collections.unmodifiableCollection(new ArrayList<>(obj))
-                : Collections.emptyList();
+    /**
+     * Creates a defensive immutable copy of a collection or returns an empty 
immutable list if the input is null or empty.
+     * This method is useful when creating immutable objects to ensure 
collection fields cannot be modified by external code.
+     *
+     * @param source the source collection to create an immutable copy from
+     * @param <T> the type of elements in the collection
+     * @return an unmodifiable view of the collection, or an empty list if the 
input is null or empty
+     * @throws NullPointerException if the collection contains null elements

Review Comment:
   Why do we do this? In general, lists with null elements are OK, though they 
might be wrong in a specific case. However if null elements are wrong in the 
specific case I'd expect the source list to already have checked that. 



-- 
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: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to