diff --git a/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java b/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java index fb99593c90..9bcc384234 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java +++ b/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java @@ -313,12 +313,8 @@ public final class ModelUtils public static List mergeRepositoryLists( List dominant, List recessive ) { - List repositories = new ArrayList<>(); - for ( Repository repository : dominant ) - { - repositories.add( repository ); - } + List repositories = new ArrayList<>( dominant ); for ( Repository repository : recessive ) { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java index b6e3c0c96e..f980f5ab47 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java @@ -139,7 +139,7 @@ public class DefaultClasspathTransformation if ( exits != null && exits.size() > 0 ) { - MetadataGraphEdge[] sortedExits = exits.toArray( new MetadataGraphEdge[exits.size()] ); + MetadataGraphEdge[] sortedExits = exits.toArray( new MetadataGraphEdge[0] ); Arrays.sort( sortedExits , new Comparator() diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java index 2b3108a47f..24b36dda31 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java @@ -49,6 +49,7 @@ import org.eclipse.aether.resolution.VersionRangeRequest; import org.eclipse.aether.resolution.VersionRangeResolutionException; import org.eclipse.aether.resolution.VersionRangeResult; + /** * A model resolver to assist building of projects. This resolver gives priority to those repositories that have been * declared in the POM. @@ -91,9 +92,7 @@ public class ProjectModelResolver this.resolver = resolver; this.remoteRepositoryManager = remoteRepositoryManager; this.pomRepositories = new ArrayList<>(); - List externalRepositories = new ArrayList<>(); - externalRepositories.addAll( repositories ); - this.externalRepositories = Collections.unmodifiableList( externalRepositories ); + this.externalRepositories = Collections.unmodifiableList( new ArrayList<>( repositories ) ); this.repositories = new ArrayList<>(); this.repositories.addAll( externalRepositories ); this.repositoryMerging = repositoryMerging; diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java index 40db38994d..1591573f62 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java @@ -69,7 +69,7 @@ public class DefaultToolchainManagerPrivate } } - return toRet.toArray( new ToolchainPrivate[toRet.size()] ); + return toRet.toArray( new ToolchainPrivate[0] ); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java index a8572ffc9f..8a6580b699 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java @@ -50,10 +50,7 @@ public class MojoExecutorStub public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { - for ( MojoExecution mojoExecution : mojoExecutions ) - { - executions.add( mojoExecution ); - } + executions.addAll(mojoExecutions); } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java b/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java index 8b2d9b70ab..08403b649d 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java @@ -115,7 +115,7 @@ public class CleanArgument } else { - cleanArgs = cleaned.toArray( new String[cleanedSz] ); + cleanArgs = cleaned.toArray( new String[0] ); } return cleanArgs; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 6a1a34ad55..f7ceda2422 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -384,7 +384,7 @@ public class MavenCli } } - mavenConfig = cliManager.parse( args.toArray( new String[args.size()] ) ); + mavenConfig = cliManager.parse( args.toArray( new String[0] ) ); List unrecongized = mavenConfig.getArgList(); if ( !unrecongized.isEmpty() ) { @@ -1196,7 +1196,7 @@ public class MavenCli sb.append( String.format( "%s\n", configurationProcessor.getClass().getName() ) ); } } - sb.append( String.format( "\n" ) ); + sb.append( "\n" ); throw new Exception( sb.toString() ); } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java index c95cacbfd7..25982cd6d8 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java @@ -263,9 +263,8 @@ public class StringSearchModelInterpolator fields.add( new ObjectField( currentField ) ); } } - } - this.fields = fields.toArray( new CacheField[fields.size()] ); + this.fields = fields.toArray( new CacheField[0] ); } diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java index 6818453469..338f4ff8ad 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java @@ -89,9 +89,7 @@ class DefaultModelResolver this.versionRangeResolver = versionRangeResolver; this.remoteRepositoryManager = remoteRepositoryManager; this.repositories = repositories; - List externalRepositories = new ArrayList<>(); - externalRepositories.addAll( repositories ); - this.externalRepositories = Collections.unmodifiableList( externalRepositories ); + this.externalRepositories = Collections.unmodifiableList( new ArrayList<>( repositories ) ); this.repositoryIds = new HashSet<>(); }