diff --git a/core/pom.xml b/core/pom.xml index 9fdc17af6e21b9b88ed441f44c3f86d85acbae6d..98712832434c5df5d5f6a20038d6a7abdcfcf217 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -241,7 +241,7 @@ org.jvnet.hudson xstream - 1.3-hudson-1 + 1.3-hudson-2 jfree diff --git a/core/src/main/java/hudson/util/RobustReflectionConverter.java b/core/src/main/java/hudson/util/RobustReflectionConverter.java index 31e7e34be94fd15b4e6a6ee1ec74b9213ee6583e..434bfd072b9dd4aa7bddb45d60ea9fa33b1275f8 100644 --- a/core/src/main/java/hudson/util/RobustReflectionConverter.java +++ b/core/src/main/java/hudson/util/RobustReflectionConverter.java @@ -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); } diff --git a/core/src/test/java/hudson/util/Point.java b/core/src/test/java/hudson/util/Point.java new file mode 100644 index 0000000000000000000000000000000000000000..54599084792ac14fb924a94fee14cf4ed80e1720 --- /dev/null +++ b/core/src/test/java/hudson/util/Point.java @@ -0,0 +1,8 @@ +package hudson.util; + +/** + * @author Kohsuke Kawaguchi +*/ +public class Point { + int x,y; +} diff --git a/core/src/test/java/hudson/util/RobustReflectionConverterTest.java b/core/src/test/java/hudson/util/RobustReflectionConverterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e28e97a42fcb63d6a60b7a5b46ab98b192b3a0a1 --- /dev/null +++ b/core/src/test/java/hudson/util/RobustReflectionConverterTest.java @@ -0,0 +1,32 @@ +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 + ">123'); + } + + public void testIfWeNeedWorkaround() { + try { + read(new XStream()); + fail(); + } catch (ConversionException e) { + // expected + assertTrue(e.getMessage().contains("z")); + } + } +}