XStream
  1. XStream
  2. XSTR-515

Improve XStream's setClassLoader() method

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.3.1
    • Component/s: Core
    • Labels:
      None

      Description

      The setClassLoader() method is supposed to allow to pass the custom classloader to the XStream object.
      However, if, for example, you use it for XML to object serialization it is already too late. Speaking in Java, the following code:

      XStream x1 = new XStream();
      x1.setClassloader( someClassloader );
      x1.fromXML( someInputStream );

      will result com.thoughtworks.xstream.mapper.CannotResolveClassException if, the XStream class is loaded with the different classloader than the one referenced in the XML.
      The following code would just work fine:

      XStream x1 = new XStream( null, null, someClassloader );
      x1.fromXML( someInputStream );

      This is most likely because of setupAliases() which is called from within the constructor would look for annotations and those annotations would not be reachable at the time of XStream object creation (see the first use case).

      The setClassLoader() method should either provide warning in its Javadoc or reinit internal XStream state.

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Mindaugas Žakšauskas
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: