Skip to content

Commit c44e60d

Browse files
committed
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.
1 parent adce718 commit c44e60d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/main/java/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.Serial;
3131
import java.io.Serializable;
3232
import java.util.ArrayList;
33+
import java.util.Collections;
3334
import java.util.HashMap;
3435
import java.util.List;
3536
import java.util.Map;
@@ -108,7 +109,7 @@ public ScriptlerBuilder(
108109
@CheckForNull List<Parameter> parameters) {
109110
this.builderId = builderId;
110111
this.scriptId = scriptId;
111-
this.parameters = parameters == null ? List.of() : List.copyOf(parameters);
112+
this.parameters = new ArrayList<>(parameters == null ? List.of() : parameters);
112113
this.propagateParams = propagateParams;
113114
}
114115

@@ -180,7 +181,7 @@ public Parameter[] getParameters() {
180181

181182
@NonNull
182183
public List<Parameter> getParametersList() {
183-
return parameters;
184+
return Collections.unmodifiableList(parameters);
184185
}
185186

186187
public String getBuilderId() {

src/main/resources/META-INF/hudson.remoting.ClassFilter

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)