Bug 211146

Summary: Fields and methods of parameterized type introduced by ITDs become raw types after weaving
Product: [Tools] AspectJ Reporter: Dmitry Amelin <amelin-dmitry>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: aclement, vb
Version: DEVELOPMENT   
Target Milestone: 1.6.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Isolated example classes, aspect and compile commands none

Description Dmitry Amelin CLA 2007-11-27 19:01:01 EST
Created attachment 83915 [details]
Isolated example classes, aspect and compile commands

Build ID: M20071023-1652

Steps To Reproduce:
1. Create empty class.
2. Create aspect, which introduces ITD method returning collection parameterized by String - public Collection<String> getStrings().
3. Weave classes.
4. Create class with main method, add string to collection and iterate collection with enhanced for loop.
5. Try to compile with java compiler - it won't.

More information:
If you compile classes in one compilation process, everything works fine as calls to fields/methods of parameterized type is preceded with casts.
Comment 1 Andrew Clement CLA 2008-08-21 19:13:52 EDT
Firstly we need to know if the generics information is preserved in how the ITD is captured post compile (and pre weave).

In ResolvedMemberImpl.write() we are writing out an EclipseResolvedMember that represents the ITD.  The signature is considered to be: ()Ljava/util/List; whilst the generics sig (our internal take on it) is <>()Pjava/util/List<Ljava/lang/String;>; indicating no type variables, no parameters, and a parameterized List as the return value.  Because the signatures differ we write out the parameter types and return type signatures in full (to preserve the generics info).

This is good news, the info should be there when the itd method is added to the target.

I've written a few tests for this and implemented the necessary fixes - seems to work.

I have tested:
- public ITDs with parameterized return types
- public ITDs with parameterized parameter types
- public ITDs that are generic and have parameterized return or parameter types
- public ITDs that target interfaces.
- public ITD fields of a parameterized type

For all these I've checked the class files created, not written full blown tests that exercise the functionality.  Apart from the case mentioned when the bug was raised, so I have fully checked separate compilation with another type that uses the ITD'd method.

I have not tested:
- anything other than public ITDs
- ITDs that share type variables with the target type
- the accessor methods generated on interfaces for ITD fields that target interfaces.

If someone wants to contribute more testcases, i'll contribute more fixes ;)

Samples of the kind of testcases I've created are here:
http://dev.eclipse.org/viewcvs/index.cgi/org.aspectj/modules/tests/bugs162/pr211146/?root=Tools_Project

(that link will go live in a little while once it picks up my submitted changes)