Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4676532

LTP: Unable to get XMLDecoder to use a specific class loader

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 1.4.0
    • client-libs
    • None
    • tiger
    • x86, sparc
    • solaris_8, windows_xp


      It seems to be impossible to get the XMLDecoder class to use a class loader
      other than the default systemClassLoader when decoding an XML stream. I've
      tested 2 methods to achieve this, both fail....

      This is a major issue because it is not possible for example to load
      packages into a system using the URLClassLoader and then use XMLDecoder to
      instantiate objects contained in those packages.

      The attached example demonstrates both attempts I've made to get XMLDecoder
      to use a specific ClassLoader.

      The code base attached includes a jar test.jar file which contains a simple
      test.message class.

      Running encode.sh will write a test.xml file representing an instance of
      test.message

      Running java decode will fail to load Decode the xml, putting test.jar
      in the classpath will run java -cp test.jar:. decode

      The sample code makes two attempts to use the Decoder. Both tests
      create a URLClassLoader which references test.jar

      In the first test an owner object is created which is actually the
      class test.message which has been loaded by the URLClassLoader. I then
      use this owner object as the owner of XMLDecoder.

      In the second test I instantiate XMLDecoder using reflection. The XMLDecoder
      class is loaded by URLClassLoader (which has the test.jar reference), but
      it still fails to decode.


      All tests were run with JDK 1.4.0-b92 on SPARC Solaris 9b58

            mdavidsosunw Mark Davidson (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: