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

java.awt.FileDialog is incorrectly deserialized in jdk1.2

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: avC70361 Date: 09/29/98



        The java.awt.FileDialog is incorrectly deserialized in jdk1.2 if has been serialized in jdk 1.1.6.
      The problem caused by a fact that jdk 1.1.6 permits file and directory be set to null, but jdk 1.2 replaces
      null with "". But jdk 1.2 doesn't handle this case during deserialization of jdk1.1.6 FileDialog instance and
      therefore the file and the directory fields of the desrialized instance can be null.

      Here is a test demonstrating a bug.
      ---------FileDialogTest.java--------
      import java.awt.FileDialog;
      import java.awt.Frame;
      import java.io.*;

      public class FileDialogTest {

        public static void main(String args[]) {

          FileDialog dlg = new FileDialog(new Frame());

          if (args[0].equals("write")) {

            try {

              FileOutputStream fos = new FileOutputStream(args[1]);
              ObjectOutputStream ostream = new ObjectOutputStream(fos);

              ostream.writeObject(dlg);
              ostream.flush();
              fos.close();

              System.out.println(args[1] + " is successfuly created");

            } catch(IOException e) {
              System.out.println("Unexpected exception : " + e);
            }

          } else if (args[0].equals("read")) {

            boolean failed = false;

            try {

              FileInputStream fis = new FileInputStream(args[1]);
              ObjectInputStream istream = new ObjectInputStream(fis);

              FileDialog result = (FileDialog)istream.readObject();

              String dlgFile = dlg.getFile();
              String dlgDir = dlg.getDirectory();

              String resultFile = result.getFile();
              String resultDir = result.getDirectory();

              if (dlgFile != resultFile
                  && (dlgFile == null || !dlgFile.equals(resultFile))) {
                failed = true;
                System.out.println(
                  "file expected = " + dlgFile + ", returned = " + resultFile
                );
              }

              if (dlgDir != resultDir
                  && (dlgDir == null || !dlgDir.equals(resultDir))) {
                failed = true;
                System.out.println(
                  "directory expected = " + dlgDir + ", returned = " + resultDir
                );
              }
              if (failed) {
                System.out.println(
                 "Failed. FileDialog returned is not equal to expected"
                );
              } else {
                System.out.println("Passed.");
              }
            } catch(Exception e) {
              System.out.println("Unexpected exception : " + e);
            }

          }

        }

      }
      -------------The test output----------
      In jdk 1.1.6:
      > java -version
      java version "1.1.6"
      > java FileDialogTest write file
      file is successfuly created
      > java FileDialogTest read file
      Passed.

      In jdk 1.2:
      > java -version
      java version "1.2fcs"
      Classic VM (build JDK-1.2fcs-L, green threads, sunwjit)
      > java FileDialogTest read file
      file expected = , returned = null
      directory expected = , returned = null
      Failed. FileDialog returned is not equal to expected

      ======================================================================

            dmendenhsunw David Mendenhall (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: