Skip to content

Commit

Permalink
Remove usages of ArrayUtils (#9001)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Mar 3, 2024
1 parent 02c99cb commit 77731dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.lang.ArrayUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.HttpResponse;
Expand Down Expand Up @@ -2150,8 +2149,11 @@ private Object readResolve() {

private String convertBytesToString(List<Byte> bytes) {
Collections.reverse(bytes);
Byte[] byteArray = bytes.toArray(new Byte[0]);
return new String(ArrayUtils.toPrimitive(byteArray), getCharset());
byte[] byteArray = new byte[bytes.size()];
for (int i = 0; i < byteArray.length; i++) {
byteArray[i] = bytes.get(i);
}
return new String(byteArray, getCharset());
}

public void doBuildStatus(StaplerRequest req, StaplerResponse rsp) throws IOException {
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/hudson/util/MultipartFormDataParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.lang.ArrayUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand Down Expand Up @@ -150,7 +149,11 @@ public static boolean isMultiPartForm(@CheckForNull String contentType) {
return false;
}

String[] parts = contentType.split(";");
return ArrayUtils.contains(parts, "multipart/form-data");
for (String part : contentType.split(";")) {
if ("multipart/form-data".equals(part)) {
return true;
}
}
return false;
}
}
7 changes: 4 additions & 3 deletions core/src/main/java/hudson/util/Protector.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import org.apache.commons.lang.ArrayUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand All @@ -62,8 +61,10 @@ public static String protect(String secret) {
Cipher cipher = Secret.getCipher(ALGORITHM_MODE);
cipher.init(Cipher.ENCRYPT_MODE, KEY, new IvParameterSpec(iv));
final byte[] encrypted = cipher.doFinal((secret + MAGIC).getBytes(StandardCharsets.UTF_8));
final byte[] value = ArrayUtils.addAll(iv, encrypted);
return new String(Base64.getEncoder().encode(value), StandardCharsets.UTF_8);
byte[] result = new byte[iv.length + encrypted.length];
System.arraycopy(iv, 0, result, 0, iv.length);
System.arraycopy(encrypted, 0, result, iv.length, encrypted.length);
return new String(Base64.getEncoder().encode(result), StandardCharsets.UTF_8);
} catch (GeneralSecurityException e) {
throw new Error(e); // impossible
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import java.util.stream.Collectors;
import jenkins.model.Jenkins;
import jenkins.util.SystemProperties;
import org.apache.commons.lang.ArrayUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Stapler;
Expand Down Expand Up @@ -290,8 +289,11 @@ public static class Token {
private String encode() {
String value = timestamp.toEpochMilli() + ":" + username.length() + ":" + username + ":" + path;
byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8);
byte[] byteValue = ArrayUtils.addAll(KEY.mac(valueBytes), valueBytes);
return Base64.getUrlEncoder().encodeToString(byteValue);
byte[] macBytes = KEY.mac(valueBytes);
byte[] result = new byte[macBytes.length + valueBytes.length];
System.arraycopy(macBytes, 0, result, 0, macBytes.length);
System.arraycopy(valueBytes, 0, result, macBytes.length, valueBytes.length);
return Base64.getUrlEncoder().encodeToString(result);
}

private static Token decode(String value) {
Expand Down

0 comments on commit 77731dd

Please sign in to comment.