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

java.lang.ClassNotFoundException is incompatible in jdk 1.2

    XMLWordPrintable

    Details

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

      Description



      Name: avC70361 Date: 02/11/98



        The java.lang.ClassNotFoundException fails to be deserialized when
      the serialization has been performed with earlier version of jdk(jdk 1.1.6)
      because its serialVersionUID is not the same in different java versions.

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

      public class ClassNotFoundExceptionTest {

        public static void main(String args[]) {

          ClassNotFoundException exception = new ClassNotFoundException("exception");

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

            try {

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

              ostream.writeObject(exception);
              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);

              if (!exception.toString().equals(istream.readObject().toString())) {
                System.out.println("Error");
              } else {
                System.out.println(args[1] + " is successfuly read");
              }

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

          }

        }

      }
      ------------The test output-----------
      > jdk 1.1.6
      > java ClassNotFoundExceptionTest write file
      file is successfuly created
      > java ClassNotFoundExceptionTest read file
      file is successfuly read
      > jdk 1.2
      > java ClassNotFoundExceptionTest read file
      Unexpected exception : java.io.InvalidClassException: java.lang.ClassNotFoundException; Local class not compatible: stream classdesc serialVersionUID=9176873029745254542 local class serialVersionUID=-8505499827617619318

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

        Attachments

          Activity

            People

            Assignee:
            dconnellsunw David Connelly (Inactive)
            Reporter:
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: