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

java.io.FilePermission is incorrectly deserialized in jdk1.2beta4E

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: avC70361 Date: 05/14/98



        The java.io.FilePermission is incorrectly deserialized in jdk1.2beta4E when
      it has been serialized in jkd1.2-beta3. The InvalidClassException is thrown due
      to local class incompatibility.

      Here is the test demonstrating the bug.
      -------------FilePermissionTest.java------------
      import java.io.*;

      public class FilePermissionTest {

        public static void main(String args[]) {

          FilePermission filePermission;

          String filepath = "FilePermission.ser";

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

            filePermission = new FilePermission("path", "read");

            ObjectOutputStream stream = null;

            try {

              stream = new ObjectOutputStream(new FileOutputStream(filepath));
              stream.writeObject(filePermission);
              stream.close();

            } catch(IOException e) {
              System.out.println("Couldn't write to " + filepath + " : " + e);
              System.exit(1);
            }

            System.out.println("FilePermission written successfully");

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

            ObjectInputStream stream = null;

            try {

              stream = new ObjectInputStream(new FileInputStream(filepath));
              filePermission = (FilePermission)stream.readObject();

            } catch(InvalidClassException e) {
              System.out.println("Failed:" + e);
              System.exit(1);
            } catch(Exception e) {
              System.out.println(
                "Failed: couldn't read from" + filepath + " : " + e
              );
              System.exit(1);
            }

            System.out.println("Passed");

          }

          System.exit(0);

        }

      }
      ----------------Test output----------

      On jdk1.2-beta3:
      <avv@stardust(pts/24).263> java -fullversion
      java full version "JDK-1.2beta3-N"
      <avv@stardust(pts/24).265> java FilePermissionTest write file.ser
      FilePermission written successfully
      <avv@stardust(pts/24).266> java FilePermissionTest read file.ser
      Passed

      On jdk1.2-beta4:
      <avv@stardust(pts/2).538> java -fullversion
      java full version "JDK-1.2beta4-E"
      <avv@stardust(pts/2).539> java FilePermissionTest read file.ser
      Failed:java.io.InvalidClassException: java.io.FilePermission; Local class not compatible: stream classdesc serialVersionUID=-3107630564271172646 local class serialVersionUID=1578790672454573808

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

        Attachments

          Activity

            People

            Assignee:
            mr Mark Reinhold
            Reporter:
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: