From c44e60d60fa11aedb2d0e3a6ad5008abffe2f7f8 Mon Sep 17 00:00:00 2001 From: Michael Tughan Date: Tue, 10 Dec 2024 10:13:18 -0500 Subject: [PATCH] Use `ArrayList` for storing parameters locally Instead of using the Java 11-native `List.of` and `List.copyOf` to store a copy of the parameters list locally, which aren't natively supported by XStream serialization, use `ArrayList`, which is natively supported. When returning the parameters, wrap them in an unmodifiable list to avoid unexpected external modifications. This unfortunately means that this class is not "immutable" anymore as the parameters can technically be changed, but the current code does not provide a way to accomplish that. --- .../plugins/scriptler/builder/ScriptlerBuilder.java | 5 +++-- src/main/resources/META-INF/hudson.remoting.ClassFilter | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 src/main/resources/META-INF/hudson.remoting.ClassFilter diff --git a/src/main/java/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder.java b/src/main/java/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder.java index d6191021..758f6293 100644 --- a/src/main/java/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder.java +++ b/src/main/java/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder.java @@ -30,6 +30,7 @@ import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -108,7 +109,7 @@ public ScriptlerBuilder( @CheckForNull List parameters) { this.builderId = builderId; this.scriptId = scriptId; - this.parameters = parameters == null ? List.of() : List.copyOf(parameters); + this.parameters = new ArrayList<>(parameters == null ? List.of() : parameters); this.propagateParams = propagateParams; } @@ -180,7 +181,7 @@ public Parameter[] getParameters() { @NonNull public List getParametersList() { - return parameters; + return Collections.unmodifiableList(parameters); } public String getBuilderId() { diff --git a/src/main/resources/META-INF/hudson.remoting.ClassFilter b/src/main/resources/META-INF/hudson.remoting.ClassFilter deleted file mode 100644 index d6da0060..00000000 --- a/src/main/resources/META-INF/hudson.remoting.ClassFilter +++ /dev/null @@ -1,2 +0,0 @@ -java.util.ImmutableCollections$ListN -java.util.ImmutableCollections$List12