diff --git a/changelog.html b/changelog.html index 5dcadd2832503d73a8dc49b7be8e47e4d9c92d9c..385cc0b2778a38cca307bc3bf5003bc2dc7f9630 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 a36e9b8172291cff29c28e01252d75a717447d06..98faf0a7ae2f8d04e2093a4563ff3d2e8691e310 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 a96a8c4c89711d3296d7b140c7a37a739331e1f6..f3b976ac93635bac2c739e0ef91685d92585e22f 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()); + } + }