From a58e198f8aa60dd0cb244cba338d9c48141590e5 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 10 Dec 2013 18:50:33 -0500 Subject: [PATCH] [FIXED JENKINS-20951] XmlFile.read/unmarshal needs to catch general XStreamException so as to include CannotResolveClassException, thrown when a TopLevelItem provided by a plugin is unloadable. --- changelog.html | 3 ++ core/src/main/java/hudson/XmlFile.java | 10 ++-- .../java/hudson/model/ItemGroupMixIn.java | 4 +- .../org/jvnet/hudson/test/MockFolder.java | 3 ++ .../java/hudson/model/ItemGroupMixInTest.java | 50 ++++++++++++++++++ ...xmlFileReadCannotResolveClassException.zip | Bin 0 -> 1390 bytes 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 test/src/test/java/hudson/model/ItemGroupMixInTest.java create mode 100644 test/src/test/resources/hudson/model/ItemGroupMixInTest/xmlFileReadCannotResolveClassException.zip diff --git a/changelog.html b/changelog.html index 58ccb7ea64..ca68e9c0ac 100644 --- a/changelog.html +++ b/changelog.html @@ -76,6 +76,9 @@ Upcoming changes
  • Error page should be visible even if the anonymous user does not have overall/read access. (issue 20866) +
  • + CannotResolveClassException breaks loading of entire containing folder, not just one job. + (issue 20951)
  • JavaScript errors when navigating away from a page with a build timeline widget while the timeline is loading. (pull request 1041) diff --git a/core/src/main/java/hudson/XmlFile.java b/core/src/main/java/hudson/XmlFile.java index 148578c469..00eae060e9 100644 --- a/core/src/main/java/hudson/XmlFile.java +++ b/core/src/main/java/hudson/XmlFile.java @@ -24,7 +24,7 @@ package hudson; import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.XStreamException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.StreamException; @@ -140,9 +140,7 @@ public final class XmlFile { InputStream in = new BufferedInputStream(new FileInputStream(file)); try { return xs.fromXML(in); - } catch(StreamException e) { - throw new IOException("Unable to read "+file,e); - } catch(ConversionException e) { + } catch (XStreamException e) { throw new IOException("Unable to read "+file,e); } catch(Error e) {// mostly reflection errors throw new IOException("Unable to read "+file,e); @@ -163,9 +161,7 @@ public final class XmlFile { try { // TODO: expose XStream the driver from XStream return xs.unmarshal(DEFAULT_DRIVER.createReader(in), o); - } catch (StreamException e) { - throw new IOException("Unable to read "+file,e); - } catch(ConversionException e) { + } catch (XStreamException e) { throw new IOException("Unable to read "+file,e); } catch(Error e) {// mostly reflection errors throw new IOException("Unable to read "+file,e); diff --git a/core/src/main/java/hudson/model/ItemGroupMixIn.java b/core/src/main/java/hudson/model/ItemGroupMixIn.java index a91405c3a4..5c9bbab602 100644 --- a/core/src/main/java/hudson/model/ItemGroupMixIn.java +++ b/core/src/main/java/hudson/model/ItemGroupMixIn.java @@ -40,6 +40,8 @@ import java.io.FileFilter; import java.io.IOException; import java.io.InputStream; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Defines a bunch of static methods to be used as a "mix-in" for {@link ItemGroup} @@ -99,7 +101,7 @@ public abstract class ItemGroupMixIn { V item = (V) Items.load(parent,subdir); configurations.put(key.call(item), item); } catch (IOException e) { - e.printStackTrace(); // TODO: logging + Logger.getLogger(ItemGroupMixIn.class.getName()).log(Level.WARNING, "could not load " + subdir, e); } } diff --git a/test/src/main/java/org/jvnet/hudson/test/MockFolder.java b/test/src/main/java/org/jvnet/hudson/test/MockFolder.java index cf4231c2e9..dec3e6243a 100644 --- a/test/src/main/java/org/jvnet/hudson/test/MockFolder.java +++ b/test/src/main/java/org/jvnet/hudson/test/MockFolder.java @@ -94,6 +94,9 @@ public class MockFolder extends AbstractItem implements ModifiableTopLevelItemGr } @Override public TopLevelItem getItem(String name) { + if (items == null) { + return null; // cf. parent hack in AbstractProject.onLoad + } return items.get(name); } diff --git a/test/src/test/java/hudson/model/ItemGroupMixInTest.java b/test/src/test/java/hudson/model/ItemGroupMixInTest.java new file mode 100644 index 0000000000..ddf14573db --- /dev/null +++ b/test/src/test/java/hudson/model/ItemGroupMixInTest.java @@ -0,0 +1,50 @@ +/* + * The MIT License + * + * Copyright 2013 Jesse Glick. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package hudson.model; + +import java.util.Collection; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Bug; +import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.MockFolder; +import org.jvnet.hudson.test.recipes.LocalData; + +public class ItemGroupMixInTest { + + @Rule public JenkinsRule r = new JenkinsRule(); + + @Bug(20951) + @LocalData + @Test public void xmlFileReadCannotResolveClassException() throws Exception { + MockFolder d = r.jenkins.getItemByFullName("d", MockFolder.class); + assertNotNull(d); + Collection items = d.getItems(); + assertEquals(1, items.size()); + assertEquals("valid", items.iterator().next().getName()); + } + +} diff --git a/test/src/test/resources/hudson/model/ItemGroupMixInTest/xmlFileReadCannotResolveClassException.zip b/test/src/test/resources/hudson/model/ItemGroupMixInTest/xmlFileReadCannotResolveClassException.zip new file mode 100644 index 0000000000000000000000000000000000000000..c5f4ba8211596f2ae57783c0b031d3268f4a99dd GIT binary patch literal 1390 zcmaiy&q@MO6vnTP_D6#uDoQHD@TuM19{7L8uQbcErhU;Zo}Mf+ zMSFZYet_`?S(ZqBDUA6q?f;Z7XjbF-mrfj&-70ID{xnRRv0wtO#$ z!XaLEZKtj_d)#o785VIDkHIW+sTN(ogOs3(Mo=BUvO1q~g#lI*#2ms_w+f*Tn1^5iq%A_a@FR(#mh| z%j;kjr!a*^3?mnZ8uoaL+kLKfEU#{I_0ToizWGG5piC?12FT*G!hTEm9ba5}R9B*) zRRk(rRvEP)pz!7Z7SS~dn=I}KmH^E2@JhhsB;v8*g32Dh1y*d0b)B(wxU4d92mJad zz36{}E`ZaBg2@4diz^2(jO3CmVidy7m7RYO1<_;h9?><~d$`52_wD3lCIOkakJL!d P!4 literal 0 HcmV?d00001 -- GitLab