aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-07 12:38:03 (EDT)
committerHenrik Lynggaard Hansen2012-07-07 12:38:03 (EDT)
commit1f821650065ece8b43aac21a06974cc44c3f4b64 (patch)
tree0fc83d7a74e8ae7ecac31b436967ec9ee794c1c1
parentb3f23e82c67f65adc91ce3f463f3ceb272694b80 (diff)
downloadorg.eclipse.hudson.core-1f821650065ece8b43aac21a06974cc44c3f4b64.zip
org.eclipse.hudson.core-1f821650065ece8b43aac21a06974cc44c3f4b64.tar.gz
org.eclipse.hudson.core-1f821650065ece8b43aac21a06974cc44c3f4b64.tar.bz2
Don't use toArray without providing sizerefs/changes/63/6663/1
6 Places where toArray is used with zero-sized parameter which mean the array is not used. Replace with array of correct size. Change-Id: Ia97a860d7151d92ba3eff2fa0815e749bff5e640 Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/Main.java2
-rw-r--r--hudson-core/src/main/java/hudson/matrix/LinkedLogRotator.java5
-rw-r--r--hudson-core/src/main/java/hudson/model/JDK.java2
-rw-r--r--hudson-core/src/main/java/hudson/model/UpdateSite.java4
-rw-r--r--hudson-core/src/main/java/hudson/model/User.java3
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/init/AvailablePluginManager.java5
6 files changed, 13 insertions, 8 deletions
diff --git a/hudson-core/src/main/java/hudson/Main.java b/hudson-core/src/main/java/hudson/Main.java
index a26c2c4..7944e86 100644
--- a/hudson-core/src/main/java/hudson/Main.java
+++ b/hudson-core/src/main/java/hudson/Main.java
@@ -142,7 +142,7 @@ public class Main {
List<String> cmd = new ArrayList<String>();
for( int i=1; i<args.length; i++ )
cmd.add(args[i]);
- Proc proc = new Proc.LocalProc(cmd.toArray(new String[0]),(String[])null,System.in,
+ Proc proc = new Proc.LocalProc(cmd.toArray(new String[cmd.size()]),(String[])null,System.in,
new DualOutputStream(System.out,new EncodingStream(os)));
int ret = proc.join();
diff --git a/hudson-core/src/main/java/hudson/matrix/LinkedLogRotator.java b/hudson-core/src/main/java/hudson/matrix/LinkedLogRotator.java
index 9ae1bf9..812e1d7 100644
--- a/hudson-core/src/main/java/hudson/matrix/LinkedLogRotator.java
+++ b/hudson-core/src/main/java/hudson/matrix/LinkedLogRotator.java
@@ -18,6 +18,7 @@ package hudson.matrix;
import hudson.model.Job;
import hudson.tasks.LogRotator;
+import hudson.util.RunList;
import java.io.IOException;
@@ -50,9 +51,9 @@ final class LinkedLogRotator extends LogRotator {
// Let superclass handle clearing artifacts, if configured:
super.perform(_job);
MatrixConfiguration job = (MatrixConfiguration) _job;
-
// copy it to the array because we'll be deleting builds as we go.
- for( MatrixRun r : job.getBuilds().toArray(new MatrixRun[0]) ) {
+ RunList<MatrixRun> builds = job.getBuilds();
+ for( MatrixRun r : builds.toArray(new MatrixRun[builds.size()]) ) {
if(job.getParent().getBuildByNumber(r.getNumber())==null)
r.delete();
}
diff --git a/hudson-core/src/main/java/hudson/model/JDK.java b/hudson-core/src/main/java/hudson/model/JDK.java
index def3180..94f8935 100644
--- a/hudson-core/src/main/java/hudson/model/JDK.java
+++ b/hudson-core/src/main/java/hudson/model/JDK.java
@@ -136,7 +136,7 @@ public final class JDK extends ToolInstallation implements NodeSpecific<JDK>, En
@Override
public JDK[] getInstallations() {
- return Hudson.getInstance().getJDKs().toArray(new JDK[0]);
+ return Hudson.getInstance().getJDKs().toArray(new JDK[Hudson.getInstance().getJDKs().size()]);
}
// this isn't really synchronized well since the list is Hudson.jdks :(
diff --git a/hudson-core/src/main/java/hudson/model/UpdateSite.java b/hudson-core/src/main/java/hudson/model/UpdateSite.java
index d1e95ab..09d6295 100644
--- a/hudson-core/src/main/java/hudson/model/UpdateSite.java
+++ b/hudson-core/src/main/java/hudson/model/UpdateSite.java
@@ -57,6 +57,7 @@ import java.security.cert.CertificateFactory;
import java.security.cert.TrustAnchor;
import javax.servlet.ServletContext;
+import net.sf.json.JSONArray;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.hudson.security.HudsonSecurityManager;
@@ -497,7 +498,8 @@ public class UpdateSite {
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = get(o,"compatibleSinceVersion");
this.requiredCore = get(o,"requiredCore");
- this.categories = o.has("labels") ? (String[])o.getJSONArray("labels").toArray(new String[0]) : null;
+ JSONArray labelsJsonArray = o.getJSONArray("labels");
+ this.categories = o.has("labels") ? (String[]) labelsJsonArray.toArray(new String[labelsJsonArray.size()]) : null;
for(Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute, that that name isn't maven-plugin - we ignore that one -
diff --git a/hudson-core/src/main/java/hudson/model/User.java b/hudson-core/src/main/java/hudson/model/User.java
index c07f432..98182f8 100644
--- a/hudson-core/src/main/java/hudson/model/User.java
+++ b/hudson-core/src/main/java/hudson/model/User.java
@@ -333,7 +333,8 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
*/
public static void reload() {
// iterate over an array to be concurrency-safe
- for( User u : byName.values().toArray(new User[0]) )
+ Collection<User> values = byName.values();
+ for( User u : values.toArray(new User[values.size()]) )
u.load();
}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/init/AvailablePluginManager.java b/hudson-core/src/main/java/org/eclipse/hudson/init/AvailablePluginManager.java
index b2589e4..23a35ae 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/init/AvailablePluginManager.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/init/AvailablePluginManager.java
@@ -19,6 +19,7 @@ package org.eclipse.hudson.init;
import java.io.*;
import java.net.URL;
import java.util.*;
+import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
@@ -144,8 +145,8 @@ public final class AvailablePluginManager {
displayName = get(jsonObject, "displayName");
description = get(jsonObject, "description");
type = get(jsonObject, "type");
-
- categories = jsonObject.has("categories") ? (String[]) jsonObject.getJSONArray("categories").toArray(new String[0]) : null;
+ JSONArray categoriesJsonArray = jsonObject.getJSONArray("categories");
+ categories = jsonObject.has("categories") ? (String[]) categoriesJsonArray.toArray(new String[categoriesJsonArray.size()]) : null;
for (Object jo : jsonObject.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
if (get(depObj, "name") != null