Summary: | [1.5][compiler] Incorrect generic signature attribute created for inner anonymous type | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Andrew Clement <aclement> | ||||||||
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> | ||||||||
Status: | VERIFIED FIXED | QA Contact: | |||||||||
Severity: | normal | ||||||||||
Priority: | P3 | CC: | Olivier_Thomann | ||||||||
Version: | 3.4 | ||||||||||
Target Milestone: | 3.4.1 | ||||||||||
Hardware: | PC | ||||||||||
OS: | Windows Vista | ||||||||||
Whiteboard: | |||||||||||
Attachments: |
|
Description
Andrew Clement
2008-06-05 16:08:11 EDT
To see the failure in action (without needing to javap the class), compile this file too: import java.lang.reflect.Type; public class Main { public static void main(String[]argv) throws Exception { Class c = Class.forName("a.b.Adapter$1"); Type[] ts = c.getGenericInterfaces(); for (int i = 0; i < ts.length; i++) { Type type = ts[i]; System.out.println(ts[i]); } } } when run it attempts to dereference the generic signature and goes bang due to a missing a.b.Adapter.Setter type: Exception in thread "main" java.lang.TypeNotPresentException: Type a.b.Adapter$Setter not present at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:98) at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107) at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31) at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:82) at java.lang.Class.getGenericInterfaces(Class.java:788) at Main.main(Main.java:7) Other testcase, with simple reference broken: import java.util.*; class Adapter<T> { class Setter<V> {} public <V> Setter<V> makeSetter() { return null; } } public class X<T> extends Adapter<T> { public <V> X<T>.Setter<V> makeSetter() { return new X<T>().new Setter<V>() {}; } void foo() { List<Adapter<T>.Setter<T>> l = new ArrayList<X<T>.Setter<T>>(); } } It incorrectly results in compiler errors, where it should compile clean. Problem comes from indirect references to member type Adapter.Setter through X, since X gets remembered incorrectly into the result binding. The fix is near what you suggested indeed, since it was incorrectly replacing the enclosing type of the inherited member type. The condition is a little bit different, but same spirit. Also other type of references need to be fixed in similar way. Marking for 3.4.1 Added GenericTypeSignatureTest#test021 Added GenericTypeTest#test1341-1345. Regression tests are actually: Added GenericTypeSignatureTest#test021 Added GenericTypeTest#test1342-1346. Created attachment 104134 [details]
Proposed patch
Created attachment 104298 [details]
In progress patch for 3.3.x
Created attachment 104318 [details]
Patch for 3.3.x
previous patch had extra '\n' in regression test CU name
Released patch to 3.3.x maintenance branch Released for 3.5M1 Released to 3.4 maintenance branch Fixed Released for 3.4.1 Verified for 3.5M1 using I20080805-1307 Verified for 3.4.1 using build M20080827-2000. |