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

java.lang.reflect.ReflectPermission is incorrectly deserialized

XMLWordPrintable



      Name: avC70361 Date: 05/14/98



        The java.lang.reflect.ReflectPermission is incorrectly deserialized in
      jdk1.2-beta4 when have been serialized in jdk1.2-beta3. The exception
      InvalidClassException is thrown

      Here is the test demonstarating the bug.
      --------------ReflectPermissionTest.java--------
      import java.io.*;
      import java.lang.reflect.ReflectPermission;

      public class ReflectPermissionTest {

        public static void main(String args[]) {

          ReflectPermission permission = new ReflectPermission("");

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

            ObjectOutputStream stream = null;

            try {

              stream = new ObjectOutputStream(new FileOutputStream(args[1]));
              stream.writeObject(permission);
              stream.close();

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

            System.out.println(args[1] + " written successfully");

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

            ObjectInputStream stream = null;

            try {

              stream = new ObjectInputStream(new FileInputStream(args[1]));
              permission = (ReflectPermission)stream.readObject();

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

            System.out.println("Passed");

          }

          System.exit(0);

        }

      }
      -------------The test output-----------
      Under jdk1.2-beta3:
      <avv@stardust(pts/24).297> java -fullversion
      java full version "JDK-1.2beta3-N"
      You have mail in /var/mail/avv
      <avv@stardust(pts/24).298> java ReflectPermissionTest write file.ser
      file.ser written successfully
      <avv@stardust(pts/24).299> java ReflectPermissionTest read file.ser
      Passed

      Under jdk1.2beta4:
      <avv@stardust(pts/2).560> java -fullversion
      java full version "JDK-1.2beta4-E"
      <avv@stardust(pts/2).561> java ReflectPermissionTest read file.ser
      Failed:java.io.InvalidClassException: java.security.Permission; Local class not compatible: stream classdesc serialVersionUID=-7030020599177105072 local class serialVersionUID=-5636570222231596674

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

            apalanissunw Anand Palaniswamy (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: