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

(reflect) Field.getGenericType() throws GenericSignatureFormatError

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 8
    • 5.0, 6
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.5.0_08"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      class GenericFailure<T>
      {
          class Nested
          {
              class Sub {}
          }
          Nested.Sub fails;
      }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      write a main with:

              Field f = GenericFailure.class.getDeclaredField("fails");
              Type t = f.getGenericType();





      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      get the generic type of the member field "fails" from class GenericFailure

      ACTUAL -
      the second line throws an "GenericSignatureFormatError"

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.reflect.GenericSignatureFormatError
              at sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:103)
              at sun.reflect.generics.parser.SignatureParser.parseSimpleClassTypeSignature(SignatureParser.java:262)
              at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignatureSuffix(SignatureParser.java:270)
              at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java:244)
              at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:228)
              at sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.java:359)
              at sun.reflect.generics.parser.SignatureParser.parseTypeSig(SignatureParser.java:157)
              at sun.reflect.generics.repository.FieldRepository.parse(FieldRepository.java:34)
              at sun.reflect.generics.repository.FieldRepository.parse(FieldRepository.java:24)
              at sun.reflect.generics.repository.AbstractRepository.<init>(AbstractRepository.java:56)
              at sun.reflect.generics.repository.FieldRepository.<init>(FieldRepository.java:30)
              at sun.reflect.generics.repository.FieldRepository.make(FieldRepository.java:48)
              at java.lang.reflect.Field.getGenericInfo(Field.java:84)
              at java.lang.reflect.Field.getGenericType(Field.java:222)
              at Main.main(Main.java:17)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.*;

      class GenericFailure<T>
      {
          class Nested
          {
              class Sub {}
          }
          Nested.Sub fails;
      }

      public class Main {
          public static void main(String[] args) {
              try
              {
                  Field f = GenericFailure.class.getDeclaredField("fails");
                  Type t = f.getGenericType();
              }
              catch (Exception e)
              {
                  System.err.println(e.toString());
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      none, but the following two similar cases are working:

      class GenericFailure<T>
      {
          class Nested
          {
              class Sub {}
          }
          Nested fails; // fails uses Nested instead Nested.Sub
      }

      and getType() instead of getGenericType() always yields the right raw type.

            darcy Joe Darcy
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: