[FIXED HUDSON-5769] Update to XStream 1.3.1-hudson-6 where I added

protected Converter createDefaultConverter().  This allows a subclass
to override the default converter (was hardcoded to ReflectionConverter)
which is also given to the constructor of a few other converters,
most notably ThrowableConverter.  Override this method in XStream2 to
provide a RobustReflectionConverter so missing fields in classes
extending Throwable are handled properly.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@28141 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
mindless committed 2010-03-02 18:55:42 +00:00
1 parent e576992c90
commit 48df625a44
3 files changed
+43 -8

No files matched your search

+3 -2
View File
@@ -1,7 +1,8 @@
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Daniel Dyer, Erik Ramfelt, Stephen Connolly, Tom Huybrechts
Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi,
Daniel Dyer, Erik Ramfelt, Stephen Connolly, Tom Huybrechts, Alan Harder
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -396,7 +397,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1-hudson-5</version>
<version>1.3.1-hudson-6</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
+8 -5
View File
@@ -70,20 +70,23 @@ public class XStream2 extends XStream {
return super.unmarshal(reader,root,dataHolder);
}
@Override
protected Converter createDefaultConverter() {
// replace default reflection converter
return new RobustReflectionConverter(getMapper(),new JVM().bestReflectionProvider());
}
private void init() {
// list up types that should be marshalled out like a value, without referencial integrity tracking.
// list up types that should be marshalled out like a value, without referencial integrity tracking.
addImmutableType(Result.class);
registerConverter(new RobustCollectionConverter(getMapper(),getReflectionProvider()),10);
registerConverter(new CopyOnWriteMap.Tree.ConverterImpl(getMapper()),10); // needs to override MapConverter
registerConverter(new DescribableList.ConverterImpl(getMapper()),10); // explicitly added to handle subtypes
registerConverter(new DescribableList.ConverterImpl(getMapper()),10); // explicitly added to handle subtypes
// this should come after all the XStream's default simpler converters,
// but before reflection-based one kicks in.
registerConverter(new AssociatedConverterImpl(this),-10);
// replace default reflection converter
registerConverter(new RobustReflectionConverter(getMapper(),new JVM().bestReflectionProvider()),-19);
}
@Override
@@ -28,7 +28,7 @@ import hudson.model.Result;
import hudson.model.Run;
/**
*
* Tests for XML serialization of java objects.
* @author Kohsuke Kawaguchi, Mike Dillon, Alan Harder
*/
public class XStream2Test extends TestCase {
@@ -66,6 +66,7 @@ public class XStream2Test extends TestCase {
/**
* Test marshal/unmarshal round trip for class/field names with _ and $ characters.
* (HUDSON-5768)
*/
public void testXmlRoundTrip() {
XStream2 xs = new XStream2();
@@ -81,4 +82,34 @@ public class XStream2Test extends TestCase {
assertEquals(xml, b.$dollar, b2.$dollar);
assertEquals(xml, b.dollar$2, b2.dollar$2);
}
private static class Baz {
private Exception myFailure;
}
/**
* Verify RobustReflectionConverter can handle missing fields in a class extending
* Throwable/Exception (default ThrowableConverter registered by XStream calls
* ReflectionConverter directly, rather than our RobustReflectionConverter replacement).
* (HUDSON-5769)
*/
public void testUnmarshalThrowableMissingField() {
Baz baz = new Baz();
baz.myFailure = new Exception("foo");
XStream2 xs = new XStream2();
String xml = xs.toXML(baz);
baz = (Baz)xs.fromXML(xml);
assertEquals("foo", baz.myFailure.getMessage());
baz = (Baz)xs.fromXML("<hudson.util.XStream2Test_-Baz><myFailure>"
+ "<missingField>true</missingField>"
+ "<detailMessage>hoho</detailMessage>"
+ "<stackTrace><trace>"
+ "hudson.util.XStream2Test.testUnmarshalThrowableMissingField(XStream2Test.java:97)"
+ "</trace></stackTrace>"
+ "</myFailure></hudson.util.XStream2Test_-Baz>");
// Object should load, despite "missingField" in XML above
assertEquals("hoho", baz.myFailure.getMessage());
}
}