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

java.text.Collator failes to be deserialized

XMLWordPrintable

    • 1.2beta4
    • sparc
    • solaris_2.5
    • Verified



      Name: avC70361 Date: 03/30/98



        While a java.text.Collator instance is deserialized an unexpected
      java.lang.Error is thrown from the java.io.ObjectInputStream.invokeObjectReader
      method. The bug appears only when the Collator instance serialized has the
      Collator.FULL_DECOMPOSITION mode set and only when using Reflection API. Without
      using Reflection API the deserialization works correctly.

      Here is the test demonstrating the bug.
      --------------------ObjectInputStreamTest.java--------------
      import java.io.ByteArrayInputStream;
      import java.io.ByteArrayOutputStream;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;
      import java.lang.reflect.Method;
      import java.text.Collator;
      import java.util.Locale;

      public class ObjectInputStreamTest {

        public void testWrite() {
          try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream ostream = new ObjectOutputStream(baos);

            Collator collator = Collator.getInstance(Locale.US);
            collator.setDecomposition(Collator.FULL_DECOMPOSITION);
            ostream.writeObject(collator);
            ostream.flush();
            baos.close();

            ObjectInputStream istream = new ObjectInputStream(
              new ByteArrayInputStream(baos.toByteArray())
            );

            istream.readObject();

            System.out.println("Test passed");

          } catch(Throwable e) {
            System.out.println("Test failed");
            e.printStackTrace();
          }
        }

        public static void main(String args[]) {
          ObjectInputStreamTest test = new ObjectInputStreamTest();
          try {
            Method method = ObjectInputStreamTest.class.getDeclaredMethod("testWrite", new Class[] {});
            method.invoke(test, new Object[] {});
          } catch(Throwable e) {
            System.out.println("Test failed");
            e.printStackTrace();
          }
        }

      }
      -------------The test output----------
      > java ObjectInputStreamTest
      Test failed
      java.lang.Error: interal error
              at java.io.ObjectInputStream.invokeObjectReader(ObjectInputStream.java:1697)
              at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1148)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:233)
              at ObjectInputStreamTest.testWrite(ObjectInputStreamTest.java:26)
              at java.lang.reflect.Method.invoke(Native Method)
              at ObjectInputStreamTest.main(ObjectInputStreamTest.java:40)

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

            lwernersunw Laura Werner (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: