gnodet commented on code in PR #2037: URL: https://github.com/apache/maven/pull/2037#discussion_r1912070489
########## 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: It's just a side effect of using `List.copyOf()`. The behavior thus surfaces to this helper methods and the javadoc mentions it. -- 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