Hi Charles,

sorry for the delay, working on the backlog ...

Charles Colbourn wrote:

> 
> Hi
> 
> I've stumbled over a bit of an oddity with Xstream across these two
> versions of Android.

actually I have no Android, so I can only assume ...

> If you have an annotated field:
> 
> @XStreamImplicit
> public ArrayList<String> myMessages = new ArrayList<String>();
> 
> and you read XML using Xstream.fromXML(string);
> 
> and test to see if your field has been populated:
> 
> if ( myMessages.size()>0 ) {#dostuff
> 
> 
> On 4.1 it will work, but 4.3 it will barf with an NPE. In other words,
> when reading the XML on 4.1 it seems to leave any fields alone that are
> not represented in the XML, whereas on 4.3 it seems to assign null to
> them.
> 
> I've got around the problem by
> 
> if ( myMessages != null && myMessages.size()>0 )
> 
> but I'd have expected it to be consistent.

It looks like XStream does not run in enhanced mode on the older Android 
version (requires stuff from sun.misc.Unsafe). In that case it cannot 
instantiate objects without running the initializers. If your implicit list 
contains no element, XStream does not know about the list member at all at 
deserialization time and leaves it alone. So the list instance must have 
been created by the Java initializers of the class.

Which version of XStream are you using? Do you have some kind of console 
where you can run com.thoughtworks.xstream.core.JVM and compare the output?

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to