Hi dev,

I use xstream-1.4.4, the latest stable release.

got the following exception trying to unmarshall an XML file.

com.thoughtworks.xstream.converters.ConversionException: Invalid reference
---- Debugging information ----
reference           : ../../Class2[257]/class3
class               : Class1
required-type       : Class1
converter-type      : 
com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /list/Class1[169]/class3
class[1]            : java.util.ArrayList
converter-type[1]   : 
idm4j.clojure.xstream.proxy$com.thoughtworks.xstream.converters.collections.CollectionConverter$0
version             : null
-------------------------------
    at 
com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:57)
    at 
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355)
    at 
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306)
    at 
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
    at 
com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    at 
com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
    at 
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at 
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
    at 
com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71)
 ...

The problematic part of XML looks like this (with my comments):

  <!-- Class2[257] -->
  <Class2>
    <!-- primary reference, resolved in cache, but not re-registered as 
Class1[257]/class3 -->
    <class3 reference="../../Class1[228]/class3"/>
  </Class2>
  <Class4>
    <!-- problematic reference, not in cache-->
    <class3 reference="../../Class2[257]/class3"/>
  </Class4>

The problem is that the reference class3 in the Class2[257] object is successfuly resolved in cache and the object found is NOT registered as "Class2[257]/class3". The reference in the next entry is chained and cannot be resolved.

The fix: change the following lines in AbstractReferenceUnmarshaller.java:

if (cache == null) {
  final ConversionException ex = new ConversionException("Invalid reference");
  ex.add("reference", reference);
  throw ex;
  }
result = cache == NULL ? null : cache;

to

if (cache == null) {
  final ConversionException ex = new ConversionException("Invalid reference");
  ex.add("reference", reference);
  throw ex;
  }
result = cache;
values.put(getCurrentReferenceKey(), cache); // !!!

Regards,
Vladimir

PS: what is the right way to report bugs? JIRA site does not allows me to 
create an account :-(


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

   http://xircles.codehaus.org/manage_email


Reply via email to