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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 5.0
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      x86, sparc
    • OS:
      solaris_8, windows_xp

      Description


      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: