United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5087240 (reflect) Constructor.getGenericParameterTypes for nested class w/ generics fail
JDK-5087240 : (reflect) Constructor.getGenericParameterTypes for nested class w/ generics fail

Details
Type:
Bug
Submit Date:
2004-08-16
Status:
Open
Updated Date:
2014-04-10
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.lang:reflect
CPU:
x86
Priority:
P3
Resolution:
Unresolved
Affected Versions:
6
Targeted Versions:
9

Related Reports
Duplicate:
Relates:
Relates:

Sub Tasks

Description
Name: js151677			Date: 08/16/2004


FULL PRODUCT VERSION :
build 1.5.0-beta2-b51

ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
Constructor.getGenericParameterTypes for a nested class fail with a parameterized type.
The number of parameters is wrong (The first is missing).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
ConstructorBugTest$Nested(ConstructorBugTest,java.util.List,long)
        class ConstructorBugTest class java.lang.Class
        java.util.List<java.lang.String> class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
        long class java.lang.Class

ACTUAL -
ConstructorBugTest$Nested(ConstructorBugTest,java.util.List,long)
        java.util.List<java.lang.String> class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
        long class java.lang.Class


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.lang.reflect.*;
import java.util.*;
public class ConstructorBugTest {
   public static void main(String... args){
      Class c = Nested.class;
      Constructor[] constructors = c.getDeclaredConstructors();
      for(Constructor cons : constructors){
         System.out.println(cons);
         Type[] types = cons.getGenericParameterTypes();
         for(Type t : types){
            System.out.println("\t" + t + " " + t.getClass());
         }
      }
   }
   private class Nested{
      Nested(List list, int x){
      }
      Nested(List<String> list, long x){
      }
   }
}

---------- END SOURCE ----------
(Incident Review ID: 297027) 
======================================================================

                                    

Comments
EVALUATION

The root cause of this problem is a difference between the Java vm and language views of a inner class constructor.  At the vm level, there is a synthetic parameter prepended to the argument list so the enclosing object reference can be passed down.  When generic information is present, that information correctly represents the source view of the constructor.  However, the existing getParameterTypes method models the vm view of the constructor.  The proper fix is having getGenericParameterTypes always model the source semantics even when generic information is not present. 

This should be addressed in a future release.

###@###.### 2004-08-18
                                     
2004-08-18
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-08-19
One the synthetic and synthesized information is available in the platform from JDK-8004729, it will be possible to better address this bug.

                                     
2012-12-08



Hardware and Software, Engineered to Work Together