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

java.util.Arrays$ArrayList serialization is incompatible between jdk 1.2 and jdk

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2.2
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Backports

        Description



        Name: avC70361 Date: 02/03/99



          The java.util.Arrays$ArrayList fails to be deserialized in jdk 1.2.2 when
        the serialization has been performed in earlier version of jdk(jdk 1.2)
        because its serialVersionUID is not the same in different jdk versions.

        Here is a test demonstrating the bug.
        ---------ArraysArrayListTest.java--------
        import java.util.*;
        import java.io.*;

        public class ArraysArrayListTest {

          public static void main(String args[]) {

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

              try {

                FileOutputStream fos = new FileOutputStream(args[1]);
                ObjectOutputStream ostream = new ObjectOutputStream(fos);

                ostream.writeObject(Arrays.asList(new Object[] {""}));
                ostream.flush();
                fos.close();

                System.out.println(args[1] + " is successfuly created");

              } catch(IOException e) {
                System.out.println("Unexpected exception : " + e);
              }

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

              try {

                FileInputStream fis = new FileInputStream(args[1]);
                ObjectInputStream istream = new ObjectInputStream(fis);

                List list = (List)istream.readObject();

                System.out.println(args[1] + " is successfuly read");

              } catch(Exception e) {
                System.out.println("Unexpected exception : " + e);
              }

            }

          }

        }
        ---------------The test output--------------
        jdk 1.2:
        <avv@viking(pts/0).295> java -version
        java version "1.2"
        Classic VM (build JDK-1.2-V, green threads, sunwjit)
        <avv@viking(pts/0).296> java ArraysArrayListTest write file.ser
        file.ser is successfuly created
        <avv@viking(pts/0).297> java ArraysArrayListTest read file.ser
        file.ser is successfuly read

        jdk 1.2.2:
        <avv@viking(pts/0).299> java -version
        java version "1.2.2"
        Classic VM (build JDK-1.2.2-D, green threads, sunwjit)
        <avv@viking(pts/0).300> java ArraysArrayListTest read file.ser
        Unexpected exception : java.io.InvalidClassException: java.util.Arrays$ArrayList; Local class not compatible: stream classdesc serialVersionUID=-2764017481108945198 local class serialVersionUID=6713627758412895285

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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jjb Josh Bloch
                  Reporter:
                  duke J. Duke (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: