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

(ann) java.lang.annotation.AnnotationTypeMismatchException could not be serialized

    Details

    • Subcomponent:
    • Resolved In Build:
      b127
    • CPU:
      generic
    • OS:
      generic

      Description

      The instance of the java.lang.annotation.AnnotationTypeMismatchException class
      could not be serialized because the AnnotationTypeMismatchException class has
      non-transient and non-static field 'element' of non-serializable
      class java.lang.reflect.Method.
       
      The minimized test to reproduce the bug:
      --- Test.java ---
      import java.lang.annotation.AnnotationTypeMismatchException;
      import java.lang.reflect.Method;
      import java.io.*;

      public class Test {

          public static void main(String argv[]) throws Exception {
              Method[] meths = MyClass.class.getDeclaredMethods();
              System.out.println("meths[0]: " + meths[0].toString());

              AnnotationTypeMismatchException obj =
                      new AnnotationTypeMismatchException(meths[0], "foundType");
              
              ObjectOutputStream oos = new ObjectOutputStream(
      new FileOutputStream("test.ser"));
              System.out.println("Serializing AnnotationTypeMismatchException ...");
              oos.writeObject(obj);
      oos.close();
              System.out.println("PASSED.");
          }
          
      }

      class MyClass {

          public MyClass() {
              super();
          }
          
          public String dummyMethod() {
              return "";
          }

      }
      --- end-of-Test.java ---


      Test output:
      -----------
      <gyi@mars> java Test
      meths[0]: public java.lang.String MyClass.dummyMethod()
      Serializing AnnotationTypeMismatchException ...
      Exception in thread "main" java.io.NotSerializableException: java.lang.reflect.Method
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
              at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
              at Test.main(Test.java:16)

      ###@###.### 2005-2-08 16:53:49 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                ygaevsky Yuri Gaevsky
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: