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

java.text.BreakIterator is incorrectly deserialized

XMLWordPrintable

    • sparc
    • solaris_2.5



      Name: avC70361 Date: 05/15/98



        The java.text.BreakIterator is incorrectly deserialized in
      jdk1.2-beta4 when have been serialized in jdk1.2beta3. The IOException is
      thrown.

      Here is the test demonstarating the bug.
      --------------BreakIteratorTest.java--------
      import java.io.*;
      import java.text.BreakIterator;
      import java.util.Locale;

      public class BreakIteratorTest {

        public static void main(String args[]) {

          String names[] = new String[] {
            "character instance",
            "line instance",
            "sentence instance",
            "word instance"
          };

          BreakIterator iterators[] = new BreakIterator[] {
            BreakIterator.getCharacterInstance(Locale.US),
            BreakIterator.getLineInstance(Locale.US),
            BreakIterator.getSentenceInstance(Locale.US),
            BreakIterator.getWordInstance(Locale.US)
          };

          int errors = 0;

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

            ObjectOutputStream stream = null;

            try {
              stream = new ObjectOutputStream(new FileOutputStream(args[1]));
            } catch(IOException e) {
              System.out.println("Couldn't write to " + args[1] + " : " + e);
              System.exit(1);
            }


            for(int i = 0; i < iterators.length; i++) {
              try {
                stream.writeObject(iterators[i]);
              } catch(IOException e) {
                System.out.println("Couldn't write " + iterators[i] + " : " + e);
                errors++;
              }
            }

            try {
              stream.close();
            } catch(IOException e) {
              System.out.println("Couldn't close " + args[1] + " : " + e);
              System.exit(1);
            }

            if (errors == 0) {
              System.out.println(args[1] + " written successfully");
              System.exit(0);
            } else {
              System.exit(1);
            }
          } else if (args[0].equals("read")) {

            ObjectInputStream stream = null;

            try {
              stream = new ObjectInputStream(new FileInputStream(args[1]));
            } catch(Exception e) {
              System.out.println(
                "Failed: couldn't read from " + args[1] + " : " + e
              );
            }

            for(int i = 0; i < iterators.length; i++) {
              try {
                iterators[i] = (BreakIterator)stream.readObject();
              } catch(Exception e) {
                System.out.println("Deserialization failed for " + names[i] + " : " + e);
                errors++;
              }
            }

            if (errors == 0) {
              System.out.println("Passed");
              System.exit(0);
            } else {
              System.exit(1);
            }
          }
        }
      }
      -------------The test output-----------
      Under jdk1.2beta3:
      <avv@stardust(pts/24).431> java -fullversion
      java full version "JDK-1.2beta3-N"
      <avv@stardust(pts/24).432> java BreakIteratorTest write file.ser
      file.ser written successfully
      <avv@stardust(pts/24).433> java BreakIteratorTest read file.ser
      Passed

      Under jdk1.2beta4:
      <avv@stardust(pts/2).587> java -fullversion
      java full version "JDK-1.2beta4-E"
      <avv@stardust(pts/2).588> java BreakIteratorTest read file.ser
      Deserialization failed for character instance : java.io.InvalidClassException: java.text.SimpleTextBoundary; Local class not compatible: stream classdesc serialVersionUID=1157885080896561917 local class serialVersionUID=-5295413901405969138
      Deserialization failed for line instance : java.io.InvalidClassException: java.text.BreakIterator; Local class not compatible: stream classdesc serialVersionUID=9095887107768512165 local class serialVersionUID=7187754529414767982
      Deserialization failed for word instance : java.io.StreamCorruptedException: Type code out of range, is 0

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

            rgillamsunw Richard Gillam (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: