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

java.awt.ScrollPane.readObject() causes compatibility problem

XMLWordPrintable



      Name: ooR10001 Date: 04/23/2001


      Method readObject() in java.awt.ScrollPane incorrectly deserializes object
      from a stream made under previous version of JDK. This is a compatibility
      problem.

      Following test shows this bug:

      This code should be executed under jdk1.3. It makes a stream with serialized
      instance of java.awt.ScrollPane.
      -----------------
      import java.awt.ScrollPane;

      public class t {

        public static void main(String[] args) {
            try {
                java.io.FileOutputStream fos =
                        new java.io.FileOutputStream("test.ser");
                java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(fos);
                ScrollPane ex = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
                System.out.println("To stream: " + ex.getScrollbarDisplayPolicy());
                oos.writeObject(ex);
                oos.close();
                fos.close();
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
      }
      -----------------

      Output: (shows value of scrollbarDisplayPolicy)
      ----------------
      To stream: 1
      ----------------

      Following code should be exucuted under jdk1.4. It is deserialize an object from
      a stream and shows deserialized scrollbarDisplayPolicy.

      ---------------------
      public class t {

        public static void main(String[] args) {
            try {
                java.io.FileInputStream fis =
                        new java.io.FileInputStream("test.ser");
                java.io.ObjectInputStream ois = new java.io.ObjectInputStream(fis);
                ScrollPane x = (ScrollPane)ois.readObject();
                System.out.println("From stream: " + x.getScrollbarDisplayPolicy());
                ois.close();
                fis.close();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
       }
      ---------------------

      Output:
      -------------------
      >From stream: 0
      -------------------


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

            mwarressunw Michael Warres (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: