Skip to content

Commit

Permalink
[FIXED JENKINS-20951] XmlFile.read/unmarshal needs to catch general X…
Browse files Browse the repository at this point in the history
…StreamException so as to include CannotResolveClassException, thrown when a TopLevelItem provided by a plugin is unloadable.

(cherry picked from commit a58e198)

Conflicts:
	changelog.html
	core/src/main/java/hudson/XmlFile.java
  • Loading branch information
jglick authored and olivergondza committed Jan 9, 2014
1 parent 9144cec commit fb0c7db
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
10 changes: 3 additions & 7 deletions core/src/main/java/hudson/XmlFile.java
Expand Up @@ -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;
Expand Down Expand Up @@ -141,9 +141,7 @@ public Object read() throws IOException {
InputStream in = new BufferedInputStream(new FileInputStream(file));
try {
return xs.fromXML(in);
} catch(StreamException e) {
throw new IOException2("Unable to read "+file,e);
} catch(ConversionException e) {
} catch (XStreamException e) {
throw new IOException2("Unable to read "+file,e);
} catch(Error e) {// mostly reflection errors
throw new IOException2("Unable to read "+file,e);
Expand All @@ -164,9 +162,7 @@ public Object unmarshal( Object o ) throws IOException {
try {
// TODO: expose XStream the driver from XStream
return xs.unmarshal(DEFAULT_DRIVER.createReader(in), o);
} catch (StreamException e) {
throw new IOException2("Unable to read "+file,e);
} catch(ConversionException e) {
} catch (XStreamException e) {
throw new IOException2("Unable to read "+file,e);
} catch(Error e) {// mostly reflection errors
throw new IOException2("Unable to read "+file,e);
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/hudson/model/ItemGroupMixIn.java
Expand Up @@ -40,6 +40,8 @@
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}
Expand Down Expand Up @@ -99,7 +101,7 @@ public boolean accept(File child) {
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);
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/src/main/java/org/jvnet/hudson/test/MockFolder.java
Expand Up @@ -92,6 +92,9 @@ public String call(TopLevelItem item) {
}

@Override public TopLevelItem getItem(String name) {
if (items == null) {
return null; // cf. parent hack in AbstractProject.onLoad
}
return items.get(name);
}

Expand Down
50 changes: 50 additions & 0 deletions 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<TopLevelItem> items = d.getItems();
assertEquals(1, items.size());
assertEquals("valid", items.iterator().next().getName());
}

}
Binary file not shown.

0 comments on commit fb0c7db

Please sign in to comment.