Community
Participate
Working Groups
I tried different things to remove compiler warnings about generics which you get when you switch to JDK 5 and use collections. At last I fall back to JDK 1.4. The following code compiles with AspectJ 5 and JDK compliance level 1.4: public aspect SubjectAspect { private Set Subject.observers = new HashSet(); public void Subject.addObserver(SubjectObserver observer) { observers.add(observer); } ... } After switching to compliance level 5.0 I get an error message "The method add(E) in the type Set<E> is not applicable for the arguments (SubjectObserver)". I don't know if it is a similar problem like #87550 but I means for older projects which use collections that they can't switch to JDK 1.5
Created attachment 19782 [details] the problematic source code sources where the error occurs (about 180 LOC including comments) as compressed tar file (2 KB)
I've fixed this - a smaller program that shows the problem is: import java.util.*; aspect X { private Set PR91053.aSet = new HashSet(); public void PR91053.add(String s) { aSet.add(s); } } public class PR91053 { public static void main(String[]argv) { new PR91053().add("hello"); } } The problem is that when the intertype field declaration is captured we lose the fact that the Set is a raw type binding (i.e. a parameterized type where no bounds have been specified for any of the parameters) - and when we recover the binding later we create an ordinary type binding for it. Losing that information means later on when resolving the receiver of the MessageSend (Set.add) we end up in BinaryTypeBinding.getExactMethod() rather than ParameterizedTypeBinding.getExactMethod(). The former of these doesn't look at whether methods are parameterized and so thinks add(E) doesn't match add(SubjectObserver). The fix is to preserve that it is a raw type binding. I have done this by saying if the typex is parameterized but has no typeparameters then it is considered raw. That seems good enough for now but may break with some case I haven't come across yet... fix checked in, waiting on build...
Fix available in latest AspectJ Dev build, see AJ downloads page: http://eclipse.org/aspectj/downloads.php