Skip to content

Commit

Permalink
[JENKINS-41037] Prevent ConcurrentModificationException serializing L…
Browse files Browse the repository at this point in the history
…ibrariesAction.libraries
  • Loading branch information
jglick committed Sep 25, 2020
1 parent b6ab3c4 commit 7d8c008
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -48,7 +49,7 @@ class LibrariesAction extends InvisibleAction {
* A list of libraries in use.
*/
public List<LibraryRecord> getLibraries() {
return libraries;
return Collections.unmodifiableList(libraries);
}

@Extension public static class LibraryEnvironment extends EnvironmentContributor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.net.URL;
import java.nio.file.Paths;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -197,7 +198,9 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
return new LoadedClasses(name, trusted, changelog, run);
}
}
libraries.add(record);
List<LibraryRecord> newLibraries = new ArrayList<>(libraries);
newLibraries.add(record);
run.replaceAction(new LibrariesAction(newLibraries));
}
listener.getLogger().println("Loading library " + record.name + "@" + record.version);
CpsFlowExecution exec = (CpsFlowExecution) getContext().get(FlowExecution.class);
Expand Down

0 comments on commit 7d8c008

Please sign in to comment.