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

java.beans.XMLEncoder does not enocde java.net.URI objects

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 6
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b46
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
      Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.6.7-1-686 #1 Thu Jul 8 05:36:53 EDT 2004 i686 GNU/Linux
      (Debian unstable)

      A DESCRIPTION OF THE PROBLEM :
      The following code is affected by the problem:

      XMLEncoder e = new XMLEncoder( System.out);
      URI uri = new URI("/foo/bar");
      e.writeObject( uri);
      e.close();

      It results in the following error message and XML output:

      java.lang.IllegalAccessException: Class java.beans.Statement can not access a member of class java.net.URI with modifiers "private"
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(URI0);
      Continuing ...
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.4.2" class="java.beans.XMLDecoder">
      </java>

      The problem occurs, because the URI class does not provide a default constructor (which wouldn't make sense, since it's immutable).

      The problem can be solved by providing an appropriate PersistenceDelegate. It would be nice, if that could be provided with a future JDK release. If not, please at least consider throwing an exception with a better error description.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the supplied source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.4.2" class="java.beans.XMLDecoder">
       <object class="java.net.URI">
        <null/>
        <null/>
        <string>/foo/bar</string>
        <null/>
        <null/>
       </object>
      </java>

      ACTUAL -
      java.lang.IllegalAccessException: Class java.beans.Statement can not access a member of class java.net.URI with modifiers "private"
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(URI0);
      Continuing ...
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.4.2" class="java.beans.XMLDecoder">
      </java>


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.IllegalAccessException: Class java.beans.Statement can not access a member of class java.net.URI with modifiers "private"
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(URI0);
      Continuing ...


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.beans.XMLEncoder;
      import java.beans.DefaultPersistenceDelegate;
      import java.net.URI;

      public class URIEncodingBug {

      public static void main(String[] argv)
      throws Exception
      {
      XMLEncoder e = new XMLEncoder( System.out);
      URI uri = new URI("/foo/bar");
      e.writeObject( uri);
      e.close();
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Uncomment the e.setPersistenceDelegate line...
      ###@###.### 2005-03-23 22:14:53 GMT

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              svioletsunw Scott Violet (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: