When an inner type shares state with its outer type, and that shared state is generic, the signature attributes generated inside the inner class are not correct. This is not normally a problem because once created they are rarely processed again, however, Eclipse checks these things and discovers the inconsistencies, reporting an 'inconsistent class file' error when it sees a type variable referenced that is not in scope.
Here is a simple groovy program:
When this gets compiled, a field of type Reference is created in the inner type (in the InnerClassVisitor.visitConstructorCallExpression()) code, and this is added to the constructor. The signature attribute for the new field and the constructor of the inner type encodes a generic reference that isn't quite right - it refers to a type variable that isn't in scope. Here is the generic signature attribute for the constructor:
The first bit is OK, the 'D' referred to is defined by the declaring type and so visible from the inner. However the 'T' is not visible - I would have expected a reference to the raw type there:
Or, if it was being used in parameterized form:
Similarly it is wrong for the field:
T is not in scope (not declared by this type or a surrounding type).
To see this problem in Eclipse, define a project containing that code above and then create a pure java project that depends upon it. Add this file to the java project:
This code is enough to force JDT to load in the GormInstanceApi inner class and discover the inconsistency in signatures:
Inconsistent classfile encountered: The undefined type parameter T is referenced from within GormInstanceApi<D>.1
I'd propose the type of the newly created field is set to the raw type for groovy.lang.Reference, but I don't know how to create a raw ClassNode.
|Field||Original Value||New Value|
|Affects Version/s||1.8.0 [ 17222 ]|
|Component/s||bytecode [ 11336 ]|
|Component/s||class generator [ 10443 ]|
|Status||Open [ 1 ]||Closed [ 6 ]|
|Assignee||blackdrag blackdrag [ blackdrag ]|
|Fix Version/s||2.0-beta-3 [ 18244 ]|
|Fix Version/s||1.8.6 [ 18245 ]|
|Fix Version/s||1.7.11 [ 17244 ]|
|Resolution||Fixed [ 1 ]|