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


##########
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:
   In general, non null elements in list are a burden. Unless there's a 
specific semantic associated with a null value, I'd rather forbid those.  For 
example if you want to resolve a list of artifacts, passing null values makes 
absolutely no sense to me.



-- 
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