Skip to content

Commit

Permalink
[JENKINS-47779] copy list before sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
escoem committed Nov 3, 2017
1 parent 9fc6229 commit f27bdd1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/java/com/cloudbees/jenkins/support/impl/AboutJenkins.java
Expand Up @@ -62,6 +62,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -583,8 +584,7 @@ private static class AboutContent extends PrintedContent {
out.println("--------------");
out.println();
PluginManager pluginManager = jenkins.getPluginManager();
List<PluginWrapper> plugins = new ArrayList<PluginWrapper>(pluginManager.getPlugins());
Collections.sort(plugins);
Iterable<PluginWrapper> plugins = getSorted(pluginManager.getPlugins());
for (PluginWrapper w : plugins) {
if (w.isActive()) {
out.println(" * " + w.getShortName() + ":" + w.getVersion() + (w.hasUpdate()
Expand Down Expand Up @@ -705,8 +705,7 @@ public ActivePlugins(String path) {
@Override
protected void printTo(PrintWriter out) throws IOException {
PluginManager pluginManager = Helper.getActiveInstance().getPluginManager();
List<PluginWrapper> plugins = pluginManager.getPlugins();
Collections.sort(plugins);
Iterable<PluginWrapper> plugins = getSorted(pluginManager.getPlugins());
for (PluginWrapper w : plugins) {
if (w.isActive()) {
out.println(w.getShortName() + ":" + w.getVersion() + ":" + (w.isPinned() ? "pinned" : "not-pinned"));
Expand All @@ -723,8 +722,7 @@ public DisabledPlugins() {
@Override
protected void printTo(PrintWriter out) throws IOException {
PluginManager pluginManager = Helper.getActiveInstance().getPluginManager();
List<PluginWrapper> plugins = pluginManager.getPlugins();
Collections.sort(plugins);
Iterable<PluginWrapper> plugins = getSorted(pluginManager.getPlugins());
for (PluginWrapper w : plugins) {
if (!w.isActive()) {
out.println(w.getShortName() + ":" + w.getVersion() + ":" + (w.isPinned() ? "pinned" : "not-pinned"));
Expand Down Expand Up @@ -771,8 +769,7 @@ protected void printTo(PrintWriter out) throws IOException {

out.println("RUN mkdir -p /usr/share/jenkins/ref/plugins/");

List<PluginWrapper> plugins = pluginManager.getPlugins();
Collections.sort(plugins);
Iterable<PluginWrapper> plugins = getSorted(pluginManager.getPlugins());

List<PluginWrapper> activated = new ArrayList<PluginWrapper>();
List<PluginWrapper> disabled = new ArrayList<PluginWrapper>();
Expand Down Expand Up @@ -1010,4 +1007,15 @@ private class NodeChecksumsContent extends PrintedContent {
}
}

/**
* Fixes JENKINS-47779 caused by JENKINS-47713
* Not using SortedSet because of PluginWrapper doesn't implements equals and hashCode.
* @param list original list, probably an unmodifiableList
* @return new copy of the list sorted
*/
private static Iterable<PluginWrapper> getSorted(List<PluginWrapper> list) {
final List<PluginWrapper> sorted = new LinkedList<PluginWrapper>(list);
Collections.sort(sorted);
return sorted;
}
}

0 comments on commit f27bdd1

Please sign in to comment.