This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push: new e0effe20dd Use List.copyOf to make a defensive immutable copy of the input collection e0effe20dd is described below commit e0effe20ddcee4575e925292e0b727d0c8d06a8b Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Sun Jan 12 21:23:19 2025 +0100 Use List.copyOf to make a defensive immutable copy of the input collection --- .../org/apache/maven/api/services/ArtifactDeployerRequest.java | 3 ++- .../apache/maven/api/services/ArtifactInstallerRequest.java | 3 ++- .../org/apache/maven/api/services/ArtifactResolverRequest.java | 2 +- .../main/java/org/apache/maven/api/services/BaseRequest.java | 10 ---------- .../apache/maven/api/services/DependencyResolverRequest.java | 4 ++-- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerRequest.java index 38f68fbb85..3c5dba3d9f 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerRequest.java @@ -19,6 +19,7 @@ package org.apache.maven.api.services; import java.util.Collection; +import java.util.List; import org.apache.maven.api.ProducedArtifact; import org.apache.maven.api.RemoteRepository; @@ -115,7 +116,7 @@ public interface ArtifactDeployerRequest { int retryFailedDeploymentCount) { super(session); this.repository = requireNonNull(repository, "repository cannot be null"); - this.artifacts = unmodifiable(requireNonNull(artifacts, "artifacts cannot be null")); + this.artifacts = List.copyOf(requireNonNull(artifacts, "artifacts cannot be null")); this.retryFailedDeploymentCount = retryFailedDeploymentCount; } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerRequest.java index f1d7ecc89d..badf60170d 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerRequest.java @@ -20,6 +20,7 @@ package org.apache.maven.api.services; import java.util.Collection; import java.util.Collections; +import java.util.List; import org.apache.maven.api.ProducedArtifact; import org.apache.maven.api.Session; @@ -89,7 +90,7 @@ public interface ArtifactInstallerRequest { DefaultArtifactInstallerRequest(@Nonnull Session session, @Nonnull Collection<ProducedArtifact> artifacts) { super(session); - this.artifacts = unmodifiable(requireNonNull(artifacts, "artifacts cannot be null")); + this.artifacts = List.copyOf(requireNonNull(artifacts, "artifacts cannot be null")); } @Nonnull diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverRequest.java index bc59aaddac..ae937914e6 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverRequest.java @@ -119,7 +119,7 @@ public interface ArtifactResolverRequest { @Nonnull Collection<? extends ArtifactCoordinates> coordinates, @Nonnull List<RemoteRepository> repositories) { super(session); - this.coordinates = unmodifiable(requireNonNull(coordinates, "coordinates cannot be null")); + this.coordinates = List.copyOf(requireNonNull(coordinates, "coordinates cannot be null")); this.repositories = repositories; } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/BaseRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/BaseRequest.java index 2a00e4b0a5..43bbf6e0b3 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/BaseRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/BaseRequest.java @@ -18,10 +18,6 @@ */ package org.apache.maven.api.services; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - import org.apache.maven.api.ProtoSession; import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Nonnull; @@ -46,10 +42,4 @@ abstract class BaseRequest<S extends ProtoSession> { public S getSession() { return session; } - - protected static <T> Collection<T> unmodifiable(Collection<T> obj) { - return obj != null && !obj.isEmpty() - ? Collections.unmodifiableCollection(new ArrayList<>(obj)) - : Collections.emptyList(); - } } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverRequest.java index f26410a326..1a8d3529f1 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverRequest.java @@ -400,9 +400,9 @@ public interface DependencyResolverRequest { this.project = project; this.rootArtifact = rootArtifact; this.root = root; - this.dependencies = unmodifiable(requireNonNull(dependencies, "dependencies cannot be null")); + this.dependencies = List.copyOf(requireNonNull(dependencies, "dependencies cannot be null")); this.managedDependencies = - unmodifiable(requireNonNull(managedDependencies, "managedDependencies cannot be null")); + List.copyOf(requireNonNull(managedDependencies, "managedDependencies cannot be null")); this.verbose = verbose; this.pathScope = requireNonNull(pathScope, "pathScope cannot be null"); this.pathTypeFilter = (pathTypeFilter != null) ? pathTypeFilter : (t) -> true;