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

@@ -123,7 +123,7 @@ public class TestJarFile {
public File getFile(String extension) throws IOException {
File file = this.temporaryFolder.newFile();
file = new File(file.getParent(), file.getName() + "." + extension);
ZipUtil.pack(this.entries.toArray(new ZipEntrySource[this.entries.size()]), file);
ZipUtil.pack(this.entries.toArray(new ZipEntrySource[0]), file);
return file;
}

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.
@@ -61,7 +61,7 @@ public abstract class Launcher {
for (Archive archive : archives) {
urls.add(archive.getUrl());
}
return createClassLoader(urls.toArray(new URL[urls.size()]));
return createClassLoader(urls.toArray(new URL[0]));
}
/**

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) {

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 ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
extractedUrls.add(url);
}
});
return extractedUrls.toArray(new URL[extractedUrls.size()]);
return extractedUrls.toArray(new URL[0]);
}
private Stream<URL> doExtractUrls(ClassLoader classLoader) throws Exception {
@@ -158,7 +158,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
processedUrls.add(url);
}
}
return processedUrls.toArray(new URL[processedUrls.size()]);
return processedUrls.toArray(new URL[0]);
}
private List<URL> getAdditionalUrls(Class<?> testClass) throws Exception {