提交 a58e198f 编写于 作者: J Jesse Glick

[FIXED JENKINS-20951] XmlFile.read/unmarshal needs to catch general...

[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.
上级 fcdf7499
......@@ -76,6 +76,9 @@ Upcoming changes</a>
<li class=bug>
Error page should be visible even if the anonymous user does not have overall/read access.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20866">issue 20866</a>)
<li class=bug>
<code>CannotResolveClassException</code> breaks loading of entire containing folder, not just one job.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20951">issue 20951</a>)
<li class=bug>
JavaScript errors when navigating away from a page with a build timeline widget while the timeline is loading.
(<a href="https://github.com/jenkinsci/jenkins/pull/1041">pull request 1041</a>)
......
......@@ -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);
......
......@@ -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);
}
}
......
......@@ -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);
}
......
/*
* 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<TopLevelItem> items = d.getItems();
assertEquals(1, items.size());
assertEquals("valid", items.iterator().next().getName());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册