JDK-6199150 : (reflect) Bad interaction between generic signatures, inner classes, and reflection
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2004-11-23
  • Updated: 2020-01-24
  • Resolved: 2020-01-24
Related Reports
Relates :  
Relates :  
Relates :  
Description
The following program demonstrates a problem with generics, inner classes
and reflection:

$ cat -n Test.java
     1
     2  import java.lang.reflect.Field;
     3  import java.lang.reflect.Type;
     4
     5  public class Test
     6  {
     7      p1.Test3.Inner<Integer> _field;
     8
     9      public static void main(String[] args) throws Exception {
    10          Class test = Test.class;
    11          Field f = test.getDeclaredField("_field");
    12          Type t = f.getGenericType();
    13          System.out.println("type = " + t);
    14      }
    15
    16  }
$ cat -n Test3.java
     1  package p1;
     2
     3  public class Test3 {
     4      public class Inner<T> { T get() { return null; } }
     5  }
$ javac -d . Test.java Test3.java
$ java -cp . Test
type = p1.Test3.p1.Test3$Inner<java.lang.Integer>


The output is wrong and should have been:

type = p1.Test3$Inner<java.lang.Integer>

The signature generated by javac might be undesirable, but it
follows the spec.



Comments
Not reproducible as of JDK 9, a likely dup of JDK-8054213.
24-01-2020

EVALUATION Should be fixed.
09-10-2009