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

java.text.Collator serialized form in jdk1.2 is not compatible with jdk1.1.4

XMLWordPrintable

    • 1.1.6
    • generic, x86, sparc
    • generic, solaris_2.5, solaris_2.5.1, windows_nt
    • Verified



        Name: mgC56079 Date: 10/30/97


        The java.text.Collator object serialized under jdk1.1.4 fails to be
        deserialized under jdk1.2 due to the incompatibility of the class on
        jdk1.1.4 and jdk1.2 platforms.
        Reason: the serialVersionUID field is not defined.

        ==== Here is the test demonstrating the bug (CollatorTest.java) ====
        import java.io.*;
        import java.text.*;

        public class CollatorTest {

          public static void main(String args[]) {

            MyCollator obj;

            String filepath = "RBC.ser";
            if (args[0].equals("write")) {
              obj = new MyCollator();
              ObjectOutputStream stream = null;
              try {
                stream = new ObjectOutputStream(new FileOutputStream(filepath));
                stream.writeObject(obj);
                stream.close();
              } catch(IOException e) {
                System.out.println("Couldn't write to " + filepath + " : " + e);
                System.exit(1);
              }
              System.out.println("written successfully");
            } else if (args[0].equals("read")) {
              ObjectInputStream stream = null;
              try {
                stream = new ObjectInputStream(new FileInputStream(filepath));
                obj = (MyCollator)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);
          }
        }


        class MyCollator extends Collator {
          public MyCollator() {}
          public int hashCode() {return 0;}
          public int compare(String source, String target) {return 0;}
          public CollationKey getCollationKey(String source) {return null;}
        }
        ----------The test output under jdk1.1.4-----------
        #>java BigDecimalTest write
        BigDecimal written successfully
        #>java BigDecimalTest read
        Passed
        ----------The test output under jdk1.2-------------


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

        Name: mgC56079 Date: 10/30/97



        OOPS! invalid output supplied. The correct one is:
        --- jdk1.1.4 ---
        % java CollatorTest write
        written successfully
        % java CollatorTest read
        Passed
        --- jdk1.2P ---
        % java CollatorTest read
        Failed:java.io.InvalidClassException: java.text.Collator; Local class not compatible

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

              joconnersunw John Oconner (Inactive)
              mgorshen Mikhail Gorshenev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: