Skip to content

Commit

Permalink
Use ArrayList for storing parameters locally
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mtughan committed Dec 10, 2024
1 parent adce718 commit c44e60d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,7 +109,7 @@ public ScriptlerBuilder(
@CheckForNull List<Parameter> 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);

Check warning on line 112 in src/main/java/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 112 is only partially covered, one branch is missing
this.propagateParams = propagateParams;
}

Expand Down Expand Up @@ -180,7 +181,7 @@ public Parameter[] getParameters() {

@NonNull
public List<Parameter> getParametersList() {
return parameters;
return Collections.unmodifiableList(parameters);
}

public String getBuilderId() {
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/META-INF/hudson.remoting.ClassFilter

This file was deleted.

0 comments on commit c44e60d

Please sign in to comment.