提交 0335123a 编写于 作者: K kohsuke

added robust unmarshalling support to overcome findbugs incompatibility

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@12359 71c3de6d-444a-0410-be80-ed276b4c234a
上级 ea1af382
......@@ -241,7 +241,7 @@
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>xstream</artifactId>
<version>1.3-hudson-1</version>
<version>1.3-hudson-2</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
......
......@@ -10,6 +10,7 @@ import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
import com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker;
import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
import com.thoughtworks.xstream.converters.reflection.NonExistentFieldException;
import com.thoughtworks.xstream.core.util.Primitives;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
......@@ -211,6 +212,8 @@ public class RobustReflectionConverter implements Converter {
implicitCollectionsForCurrentObject = writeValueToImplicitCollection(context, value, implicitCollectionsForCurrentObject, result, fieldName);
}
}
} catch (NonExistentFieldException e) {
LOGGER.log(Level.WARNING,"Skipping a non-existent field "+e.getFieldName(),e);
} catch (CannotResolveClassException e) {
LOGGER.log(Level.WARNING,"Skipping a non-existend type",e);
}
......
package hudson.util;
/**
* @author Kohsuke Kawaguchi
*/
public class Point {
int x,y;
}
package hudson.util;
import junit.framework.TestCase;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.ConversionException;
/**
* @author Kohsuke Kawaguchi
*/
public class RobustReflectionConverterTest extends TestCase {
public void testRobustUnmarshalling() {
Point p = read(new XStream2());
assertEquals(p.x,1);
assertEquals(p.y,2);
}
private Point read(XStream xs) {
String clsName = Point.class.getName();
return (Point) xs.fromXML("<" + clsName + "><x>1</x><y>2</y><z>3</z></" + clsName + '>');
}
public void testIfWeNeedWorkaround() {
try {
read(new XStream());
fail();
} catch (ConversionException e) {
// expected
assertTrue(e.getMessage().contains("z"));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册