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

ObjectOutputStream example leads to non-working code

    XMLWordPrintable

Details

    • b29
    • x86
    • windows_2000
    • Verified

    Backports

      Description

        Name: rmT116609 Date: 11/24/2003


        A DESCRIPTION OF THE PROBLEM :
        The documentation includes an example which leads to code that doesnt work, and infact destroys a serialized file while reading it.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        FileOutputStream fos = new FileOutputStream("t.tmp");
        ObjectOutputStream oos = new ObjectOutputStream(fos);

        oos.writeInt(12345);
        oos.writeObject("Today");
        oos.writeObject(new Date());

        oos.close();
        fos.close(); //This line must be added
        ACTUAL -
        FileOutputStream fos = new FileOutputStream("t.tmp");
        ObjectOutputStream oos = new ObjectOutputStream(fos);

        oos.writeInt(12345);
        oos.writeObject("Today");
        oos.writeObject(new Date());

        oos.close();


        URL OF FAULTY DOCUMENTATION :
        http://java.sun.com/j2se/1.4.2/docs/api/java/io/ObjectOutputStream.html
        (Incident Review ID: 227388)
        ======================================================================

        Attachments

          Issue Links

            Activity

              People

                rriggs Roger Riggs
                rmandalasunw Ranjith Mandala (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: