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

JCK: java.awt.ComponentOrientation class is deserialized incorrectly

    XMLWordPrintable

Details

    • generic, sparc
    • generic, solaris_2.5

    Description



      Name: dsC58869 Date: 09/09/99



      The java.awt.ComponentOrientation class is incorrectly deserialized
      under java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-D)
      when it has been serialized with JDK1.2.2.

      Here is a minimized test:
      --- ComponentOrientationTest.java ---
      import java.awt.*;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;

      public class ComponentOrientationTest {

        public static void main(String args[]) {

          ComponentOrientation compOrient;

          if (args.length != 2) {

            System.out.println("There should be exactly two arguments");

          } else {

            String filepath = args[1] + "ComponentOrientation.ser";

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

              compOrient = ComponentOrientation.LEFT_TO_RIGHT;

              ObjectOutputStream stream = null;

              try {

                stream = new ObjectOutputStream(
                  new FileOutputStream(filepath)
                );


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

              try {

                stream.writeObject(compOrient);
                stream.close();

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

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

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

              ObjectInputStream stream = null;

              try {

                stream = new ObjectInputStream(
                  new FileInputStream(filepath)
                );

              } catch(IOException e) {
                System.out.println("Test failed: " + filepath + " not found");
                System.exit(1);
              }

              try {

                compOrient = (ComponentOrientation)stream.readObject();

              } catch(ClassNotFoundException e) {
                System.out.println("Test failed:" + e);
                System.exit(1);
              } catch(IOException e) {
                System.out.println(
                  "Test failed: couldn't read from" + filepath + " : " + e
                );
                System.exit(1);
              }

              System.out.println("Test passed");

            } else {
              System.out.println(
                "The first argument should be either 'read' or 'write'"
              );
              System.exit(1);
            }

          }

          System.exit(0);

        }

      }
      --- Writing the test data under JDK 1.3beta-O-release ----
      %java ComponentOrientationTest write tmp
      ComponentOrientation written successfully

      --- Reading the test data under JDK 1.3beta-O-release ----
      %java ComponentOrientationTest read tmp
      Test passed

      --- Reading the test data under Windows platform ---
      java ComponentOrientationTest read tmp
      Test failed: couldn't read fromtmpComponentOrientation.ser : java.io.InvalidClassException: java.awt.ComponentOrientation; Local class not compatible: stream classdesc serialVersionUID=-4113291392143563828 local class serialVersionUID=-1497425788611587381


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

      Attachments

        Activity

          People

            uwesunw Uwe Uwe (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: