From 03cca08d8db993d65f6a6b90d49b6147338cdb98 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 10 Jan 2025 17:14:24 +0000 Subject: [PATCH] [MNG-8483] Prefer Objects.requireNonNull (#2019) * Prefer Objects.requireNonNull --- .../ArtifactCoordinatesFactoryRequest.java | 14 +++++++------- .../api/services/ArtifactDeployerRequest.java | 12 ++++++------ .../maven/api/services/ArtifactFactoryRequest.java | 6 +++--- .../api/services/ArtifactInstallerRequest.java | 8 ++++---- .../api/services/ArtifactResolverRequest.java | 12 ++++++------ .../org/apache/maven/api/services/BaseRequest.java | 11 +++-------- .../DependencyCoordinatesFactoryRequest.java | 13 +++++++------ .../api/services/DependencyResolverRequest.java | 10 ++++++---- .../maven/api/services/ModelBuilderRequest.java | 14 +++++++------- .../org/apache/maven/api/services/ModelSource.java | 4 ++-- .../maven/api/services/ProjectBuilderRequest.java | 10 +++++----- .../maven/api/services/SettingsBuilderRequest.java | 6 +++--- .../java/org/apache/maven/api/services/Source.java | 4 ++-- .../api/services/ToolchainsBuilderRequest.java | 6 +++--- .../api/services/VersionRangeResolverRequest.java | 6 +++--- .../maven/api/services/VersionResolverRequest.java | 10 +++++----- .../internal/impl/DefaultVersionRangeResolver.java | 4 ++-- 17 files changed, 74 insertions(+), 76 deletions(-) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinatesFactoryRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinatesFactoryRequest.java index e887ffda11fe..cf96d490fdbf 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinatesFactoryRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinatesFactoryRequest.java @@ -25,7 +25,7 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.NotThreadSafe; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * A request for creating a {@link ArtifactCoordinates} object. @@ -57,7 +57,7 @@ public interface ArtifactCoordinatesFactoryRequest { static ArtifactCoordinatesFactoryRequest build( @Nonnull Session session, String groupId, String artifactId, String version, String extension) { return ArtifactCoordinatesFactoryRequest.builder() - .session(nonNull(session, "session")) + .session(requireNonNull(session, "session")) .groupId(groupId) .artifactId(artifactId) .version(version) @@ -75,7 +75,7 @@ static ArtifactCoordinatesFactoryRequest build( String extension, String type) { return ArtifactCoordinatesFactoryRequest.builder() - .session(nonNull(session, "session")) + .session(requireNonNull(session, "session")) .groupId(groupId) .artifactId(artifactId) .version(version) @@ -88,16 +88,16 @@ static ArtifactCoordinatesFactoryRequest build( @Nonnull static ArtifactCoordinatesFactoryRequest build(@Nonnull Session session, @Nonnull String coordinateString) { return ArtifactCoordinatesFactoryRequest.builder() - .session(nonNull(session, "session")) - .coordinateString(nonNull(coordinateString, "coordinateString")) + .session(requireNonNull(session, "session")) + .coordinateString(requireNonNull(coordinateString, "coordinateString")) .build(); } @Nonnull static ArtifactCoordinatesFactoryRequest build(@Nonnull Session session, @Nonnull ArtifactCoordinates coordinates) { return ArtifactCoordinatesFactoryRequest.builder() - .session(nonNull(session, "session")) - .groupId(nonNull(coordinates, "coordinates").getGroupId()) + .session(requireNonNull(session, "session")) + .groupId(requireNonNull(coordinates, "coordinates").getGroupId()) .artifactId(coordinates.getArtifactId()) .classifier(coordinates.getClassifier()) .version(coordinates.getVersionConstraint().asString()) 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 e82f7331e62f..38f68fbb85e1 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 @@ -27,7 +27,7 @@ import org.apache.maven.api.annotations.Immutable; import org.apache.maven.api.annotations.Nonnull; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * A request for deploying one or more artifacts to a remote repository. @@ -60,9 +60,9 @@ static ArtifactDeployerRequest build( @Nonnull RemoteRepository repository, @Nonnull Collection artifacts) { return builder() - .session(nonNull(session, "session cannot be null")) - .repository(nonNull(repository, "repository cannot be null")) - .artifacts(nonNull(artifacts, "artifacts cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .repository(requireNonNull(repository, "repository cannot be null")) + .artifacts(requireNonNull(artifacts, "artifacts cannot be null")) .build(); } @@ -114,8 +114,8 @@ private static class DefaultArtifactDeployerRequest extends BaseRequest @Nonnull Collection artifacts, int retryFailedDeploymentCount) { super(session); - this.repository = nonNull(repository, "repository cannot be null"); - this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null")); + this.repository = requireNonNull(repository, "repository cannot be null"); + this.artifacts = unmodifiable(requireNonNull(artifacts, "artifacts cannot be null")); this.retryFailedDeploymentCount = retryFailedDeploymentCount; } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactFactoryRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactFactoryRequest.java index 7e373cdd38e5..378eed160836 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactFactoryRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactFactoryRequest.java @@ -24,7 +24,7 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.NotThreadSafe; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * @@ -53,7 +53,7 @@ public interface ArtifactFactoryRequest { static ArtifactFactoryRequest build( Session session, String groupId, String artifactId, String version, String extension) { return ArtifactFactoryRequest.builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .groupId(groupId) .artifactId(artifactId) .version(version) @@ -70,7 +70,7 @@ static ArtifactFactoryRequest build( String extension, String type) { return ArtifactFactoryRequest.builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .groupId(groupId) .artifactId(artifactId) .version(version) 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 d3c0e26ccea3..f1d7ecc89dbc 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 @@ -29,7 +29,7 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * A request for installing one or more artifacts in the local repository. @@ -54,8 +54,8 @@ static ArtifactInstallerRequestBuilder builder() { @Nonnull static ArtifactInstallerRequest build(Session session, Collection artifacts) { return builder() - .session(nonNull(session, "session cannot be null")) - .artifacts(nonNull(artifacts, "artifacts cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .artifacts(requireNonNull(artifacts, "artifacts cannot be null")) .build(); } @@ -89,7 +89,7 @@ static class DefaultArtifactInstallerRequest extends BaseRequest implem DefaultArtifactInstallerRequest(@Nonnull Session session, @Nonnull Collection artifacts) { super(session); - this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null")); + this.artifacts = unmodifiable(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 24be5cbb238d..bc59aaddac2c 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 @@ -30,7 +30,7 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * A request for resolving an artifact. @@ -58,8 +58,8 @@ static ArtifactResolverRequestBuilder builder() { static ArtifactResolverRequest build( @Nonnull Session session, @Nonnull Collection coordinates) { return builder() - .session(nonNull(session, "session cannot be null")) - .coordinates(nonNull(coordinates, "coordinates cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .coordinates(requireNonNull(coordinates, "coordinates cannot be null")) .build(); } @@ -69,8 +69,8 @@ static ArtifactResolverRequest build( @Nonnull Collection coordinates, List repositories) { return builder() - .session(nonNull(session, "session cannot be null")) - .coordinates(nonNull(coordinates, "coordinates cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .coordinates(requireNonNull(coordinates, "coordinates cannot be null")) .repositories(repositories) .build(); } @@ -119,7 +119,7 @@ private static class DefaultArtifactResolverRequest extends BaseRequest @Nonnull Collection coordinates, @Nonnull List repositories) { super(session); - this.coordinates = unmodifiable(nonNull(coordinates, "coordinates cannot be null")); + this.coordinates = unmodifiable(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 59d330a9e0d9..2a00e4b0a57a 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 @@ -26,6 +26,8 @@ import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Nonnull; +import static java.util.Objects.requireNonNull; + /** * Base class for requests. * @@ -37,7 +39,7 @@ abstract class BaseRequest { private final S session; protected BaseRequest(@Nonnull S session) { - this.session = nonNull(session, "session cannot be null"); + this.session = requireNonNull(session, "session cannot be null"); } @Nonnull @@ -45,13 +47,6 @@ public S getSession() { return session; } - public static T nonNull(T obj, String message) { - if (obj == null) { - throw new IllegalArgumentException(message); - } - return obj; - } - protected static Collection unmodifiable(Collection obj) { return obj != null && !obj.isEmpty() ? Collections.unmodifiableCollection(new ArrayList<>(obj)) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinatesFactoryRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinatesFactoryRequest.java index d9cbbcb0abd7..7618aaa9921c 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinatesFactoryRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinatesFactoryRequest.java @@ -31,7 +31,7 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.NotThreadSafe; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * @@ -58,7 +58,7 @@ static DependencyCoordinatesFactoryRequest build( String extension, String type) { return DependencyCoordinatesFactoryRequest.builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .groupId(groupId) .artifactId(artifactId) .version(version) @@ -72,8 +72,9 @@ static DependencyCoordinatesFactoryRequest build( static DependencyCoordinatesFactoryRequest build( @Nonnull Session session, @Nonnull ArtifactCoordinates coordinates) { return builder() - .session(nonNull(session, "session cannot be null")) - .groupId(nonNull(coordinates, "coordinates cannot be null").getGroupId()) + .session(requireNonNull(session, "session cannot be null")) + .groupId(requireNonNull(coordinates, "coordinates cannot be null") + .getGroupId()) .artifactId(coordinates.getArtifactId()) .version(coordinates.getVersionConstraint().asString()) .classifier(coordinates.getClassifier()) @@ -84,8 +85,8 @@ static DependencyCoordinatesFactoryRequest build( @Nonnull static DependencyCoordinatesFactoryRequest build(@Nonnull Session session, @Nonnull Dependency dependency) { return builder() - .session(nonNull(session, "session cannot be null")) - .groupId(nonNull(dependency, "dependency").getGroupId()) + .session(requireNonNull(session, "session cannot be null")) + .groupId(requireNonNull(dependency, "dependency").getGroupId()) .artifactId(dependency.getArtifactId()) .version(dependency.getVersion().asString()) .classifier(dependency.getClassifier()) 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 dc8570a01aa9..f26410a326d2 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 @@ -39,6 +39,8 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; +import static java.util.Objects.requireNonNull; + /** * A request to collect the transitive dependencies and to build a dependency graph from them. There are three ways to * create a dependency graph. First, only the root dependency can be given. Second, a root dependency and direct @@ -394,15 +396,15 @@ static class DefaultDependencyResolverRequest extends BaseRequest @Nullable Predicate pathTypeFilter, @Nullable List repositories) { super(session); - this.requestType = nonNull(requestType, "requestType cannot be null"); + this.requestType = requireNonNull(requestType, "requestType cannot be null"); this.project = project; this.rootArtifact = rootArtifact; this.root = root; - this.dependencies = unmodifiable(nonNull(dependencies, "dependencies cannot be null")); + this.dependencies = unmodifiable(requireNonNull(dependencies, "dependencies cannot be null")); this.managedDependencies = - unmodifiable(nonNull(managedDependencies, "managedDependencies cannot be null")); + unmodifiable(requireNonNull(managedDependencies, "managedDependencies cannot be null")); this.verbose = verbose; - this.pathScope = nonNull(pathScope, "pathScope cannot be null"); + this.pathScope = requireNonNull(pathScope, "pathScope cannot be null"); this.pathTypeFilter = (pathTypeFilter != null) ? pathTypeFilter : (t) -> true; this.repositories = repositories; if (verbose && requestType != RequestType.COLLECT) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java index 435874c8a347..0b80828bc967 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java @@ -32,7 +32,7 @@ import org.apache.maven.api.annotations.Nullable; import org.apache.maven.api.model.Profile; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * Request used to build a {@link org.apache.maven.api.Project} using @@ -143,23 +143,23 @@ enum RepositoryMerging { @Nonnull static ModelBuilderRequest build(@Nonnull ModelBuilderRequest request, @Nonnull ModelSource source) { - return builder(nonNull(request, "request cannot be null")) - .source(nonNull(source, "source cannot be null")) + return builder(requireNonNull(request, "request cannot be null")) + .source(requireNonNull(source, "source cannot be null")) .build(); } @Nonnull static ModelBuilderRequest build(@Nonnull Session session, @Nonnull ModelSource source) { return builder() - .session(nonNull(session, "session cannot be null")) - .source(nonNull(source, "source cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .source(requireNonNull(source, "source cannot be null")) .build(); } @Nonnull static ModelBuilderRequest build(@Nonnull Session session, @Nonnull Path path) { return builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .source(ModelSource.fromPath(path)) .build(); } @@ -320,7 +320,7 @@ private static class DefaultModelBuilderRequest extends BaseRequest imp List repositories, ModelTransformer lifecycleBindingsInjector) { super(session); - this.requestType = nonNull(requestType, "requestType cannot be null"); + this.requestType = requireNonNull(requestType, "requestType cannot be null"); this.locationTracking = locationTracking; this.recursive = recursive; this.source = source; diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java index e41e7867700c..86d8718c0457 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java @@ -23,7 +23,7 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * A Source specific to load POMs. The {@link #resolve(ModelLocator, String)} method @@ -54,6 +54,6 @@ static ModelSource fromPath(@Nonnull Path path) { @Nonnull static ModelSource fromPath(@Nonnull Path path, @Nullable String location) { - return new PathSource(nonNull(path, "path cannot be null"), location); + return new PathSource(requireNonNull(path, "path cannot be null"), location); } } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java index 770d9e106740..feedd5103bf0 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java @@ -30,7 +30,7 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * Request used to build a {@link org.apache.maven.api.Project} using @@ -65,16 +65,16 @@ public interface ProjectBuilderRequest { @Nonnull static ProjectBuilderRequest build(@Nonnull Session session, @Nonnull Source source) { return builder() - .session(nonNull(session, "session cannot be null")) - .source(nonNull(source, "source cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .source(requireNonNull(source, "source cannot be null")) .build(); } @Nonnull static ProjectBuilderRequest build(@Nonnull Session session, @Nonnull Path path) { return builder() - .session(nonNull(session, "session cannot be null")) - .path(nonNull(path, "path cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .path(requireNonNull(path, "path cannot be null")) .build(); } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderRequest.java index 78a4fc5b07dc..d1c6750c455a 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderRequest.java @@ -30,7 +30,7 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * Collects settings that control the building of effective settings. @@ -95,7 +95,7 @@ static SettingsBuilderRequest build( @Nullable Source projectSettingsSource, @Nullable Source userSettingsSource) { return builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .installationSettingsSource(installationSettingsSource) .projectSettingsSource(projectSettingsSource) .userSettingsSource(userSettingsSource) @@ -109,7 +109,7 @@ static SettingsBuilderRequest build( @Nullable Path projectSettingsPath, @Nullable Path userSettingsPath) { return builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .installationSettingsSource( installationSettingsPath != null && Files.exists(installationSettingsPath) ? Source.fromPath(installationSettingsPath) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java index b882f724e35c..837b3c2dfbd1 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java @@ -27,7 +27,7 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * Provides access to the contents of a source independently of the @@ -95,6 +95,6 @@ public interface Source { */ @Nonnull static Source fromPath(@Nonnull Path path) { - return new PathSource(nonNull(path, "path cannot be null")); + return new PathSource(requireNonNull(path, "path cannot be null")); } } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderRequest.java index d6502bb562a5..ea7c5ab912a5 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderRequest.java @@ -28,7 +28,7 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * @@ -61,7 +61,7 @@ static ToolchainsBuilderRequest build( @Nullable Source installationToolchainsFile, @Nullable Source userToolchainsSource) { return builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .installationToolchainsSource(installationToolchainsFile) .userToolchainsSource(userToolchainsSource) .build(); @@ -73,7 +73,7 @@ static ToolchainsBuilderRequest build( @Nullable Path installationToolchainsFile, @Nullable Path userToolchainsPath) { return builder() - .session(nonNull(session, "session cannot be null")) + .session(requireNonNull(session, "session cannot be null")) .installationToolchainsSource( installationToolchainsFile != null && Files.exists(installationToolchainsFile) ? Source.fromPath(installationToolchainsFile) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionRangeResolverRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionRangeResolverRequest.java index cd1eb9ce65ad..d563091dbebd 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionRangeResolverRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionRangeResolverRequest.java @@ -28,7 +28,7 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * @@ -58,8 +58,8 @@ static VersionRangeResolverRequest build( @Nonnull ArtifactCoordinates artifactCoordinates, @Nullable List repositories) { return builder() - .session(nonNull(session, "session cannot be null")) - .artifactCoordinates(nonNull(artifactCoordinates, "artifactCoordinates cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .artifactCoordinates(requireNonNull(artifactCoordinates, "artifactCoordinates cannot be null")) .repositories(repositories) .build(); } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolverRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolverRequest.java index 5c7032a6e595..71a9a558eb76 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolverRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolverRequest.java @@ -28,7 +28,7 @@ import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.Nullable; -import static org.apache.maven.api.services.BaseRequest.nonNull; +import static java.util.Objects.requireNonNull; /** * @@ -49,8 +49,8 @@ public interface VersionResolverRequest { @Nonnull static VersionResolverRequest build(@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) { return builder() - .session(nonNull(session, "session cannot be null")) - .artifactCoordinates(nonNull(artifactCoordinates, "artifactCoordinates cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .artifactCoordinates(requireNonNull(artifactCoordinates, "artifactCoordinates cannot be null")) .build(); } @@ -60,8 +60,8 @@ static VersionResolverRequest build( @Nonnull ArtifactCoordinates artifactCoordinates, @Nullable List repositories) { return builder() - .session(nonNull(session, "session cannot be null")) - .artifactCoordinates(nonNull(artifactCoordinates, "artifactCoordinates cannot be null")) + .session(requireNonNull(session, "session cannot be null")) + .artifactCoordinates(requireNonNull(artifactCoordinates, "artifactCoordinates cannot be null")) .repositories(repositories) .build(); } diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java index dbea333e3cf6..f3006e7f3da2 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java @@ -38,8 +38,8 @@ import org.eclipse.aether.resolution.VersionRangeResolutionException; import org.eclipse.aether.resolution.VersionRangeResult; +import static java.util.Objects.requireNonNull; import static org.apache.maven.internal.impl.Utils.map; -import static org.apache.maven.internal.impl.Utils.nonNull; @Named @Singleton @@ -55,7 +55,7 @@ public DefaultVersionRangeResolver(RepositorySystem repositorySystem) { @Override public VersionRangeResolverResult resolve(VersionRangeResolverRequest request) throws VersionRangeResolverException { - nonNull(request, "request"); + requireNonNull(request, "request"); InternalSession session = InternalSession.from(request.getSession()); try {