Polish Collection.toArray

Consistently use `StringUtils.toStringArray`, `ClassUtils.toClassArray`
or zero length when converting collections to arrays.

Fixes gh-12160
This commit is contained in:
Phillip Webb
2018-02-22 21:10:02 -08:00
parent 358adcd6e3
commit 4b9c3c137e
84 changed files with 210 additions and 189 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -369,7 +369,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
addResources(urls);
addProjectClasses(urls);
addDependencies(urls);
return urls.toArray(new URL[urls.size()]);
return urls.toArray(new URL[0]);
}
catch (IOException ex) {
throw new MojoExecutionException("Unable to build classpath", ex);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -262,7 +262,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
if (!this.includeSystemScope) {
filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
}
return filters.toArray(new ArtifactsFilter[filters.size()]);
return filters.toArray(new ArtifactsFilter[0]);
}
private LaunchScript getLaunchScript() throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ class RunArguments {
}
public String[] asArray() {
return this.args.toArray(new String[this.args.size()]);
return this.args.toArray(new String[0]);
}
private static String[] parseArgs(String arguments) {

View File

@@ -71,7 +71,7 @@ public class RunMojo extends AbstractRunMojo {
new JavaExecutable().toString());
Runtime.getRuntime()
.addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
int exitCode = runProcess.run(true, args.toArray(new String[args.size()]));
int exitCode = runProcess.run(true, args.toArray(new String[0]));
if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) {
return;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,7 +105,7 @@ public class StartMojo extends AbstractRunMojo {
try {
RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString());
runProcess.run(false, args.toArray(new String[args.size()]));
runProcess.run(false, args.toArray(new String[0]));
return runProcess;
}
catch (Exception ex) {