From bdbac284723940e5b2dfd37dd194524305de29c2 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 11 Nov 2013 11:54:58 -0500 Subject: [PATCH] [FIXED JENKINS-20415] Lack of type safety in JENKINS-20143 fix sometimes caused CCEs. --- changelog.html | 3 +++ core/src/main/java/hudson/model/ListView.java | 10 ++++------ .../test/java/hudson/model/ListViewTest.java | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/changelog.html b/changelog.html index 5dcadd2832..385cc0b277 100644 --- a/changelog.html +++ b/changelog.html @@ -69,6 +69,9 @@ Upcoming changes (issue 20191)
  • Collect and report JVM crash dump files to assist trouble-shooting +
  • + ClassCastExceptions sometimes shown from views set to be recursive. + (issue 20415)
  • Show different “up” link for jobs in folders. (issue 20106) diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index a36e9b8172..98faf0a7ae 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -186,14 +186,12 @@ public class ListView extends View implements Saveable { } private List expand(Collection items, List allItems) { - for (Item item : items) { + for (TopLevelItem item : items) { if (item instanceof ItemGroup) { - ItemGroup ig = (ItemGroup) item; - expand(ig.getItems(), allItems); - } - if (item instanceof TopLevelItem) { - allItems.add((TopLevelItem) item); + ItemGroup ig = (ItemGroup) item; + expand(Util.filter(ig.getItems(), TopLevelItem.class), allItems); } + allItems.add(item); } return allItems; } diff --git a/test/src/test/java/hudson/model/ListViewTest.java b/test/src/test/java/hudson/model/ListViewTest.java index a96a8c4c89..f3b976ac93 100644 --- a/test/src/test/java/hudson/model/ListViewTest.java +++ b/test/src/test/java/hudson/model/ListViewTest.java @@ -40,6 +40,10 @@ import org.xml.sax.SAXException; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import hudson.matrix.AxisList; +import hudson.matrix.MatrixProject; +import hudson.matrix.TextAxis; +import java.util.Collections; public class ListViewTest { @@ -95,4 +99,17 @@ public class ListViewTest { webClient.getPage(top, link.getHrefAttribute()); } + @Bug(20415) + @Test public void nonTopLevelItemGroup() throws Exception { + MatrixProject mp = j.createMatrixProject(); + mp.setAxes(new AxisList(new TextAxis("axis", "one", "two"))); + assertEquals(2, mp.getItems().size()); + ListView v = new ListView("v"); + j.jenkins.addView(v); + v.setIncludeRegex(".*"); + v.setRecurse(true); + // Note: did not manage to reproduce CCE until I changed expand to use ‘for (TopLevelItem item : items)’ rather than ‘for (Item item : items)’; perhaps a compiler-specific issue? + assertEquals(Collections.singletonList(mp), v.getItems()); + } + } -- GitLab