Bug 91053 - Generics problem with Set - does not compile with AspectJ 5
Summary: Generics problem with Set - does not compile with AspectJ 5
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0M2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.5.0 M3   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-11 17:15 EDT by Oliver CLA
Modified: 2005-05-09 03:20 EDT (History)
0 users

See Also:


Attachments
the problematic source code (1.71 KB, application/x-gzip)
2005-04-11 17:24 EDT, Oliver CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver CLA 2005-04-11 17:15:13 EDT
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
Comment 1 Oliver CLA 2005-04-11 17:24:44 EDT
Created attachment 19782 [details]
the problematic source code

sources where the error occurs (about 180 LOC including comments)
as compressed tar file (2 KB)
Comment 2 Andrew Clement CLA 2005-05-06 11:20:42 EDT
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...
Comment 3 Andrew Clement CLA 2005-05-09 03:20:01 EDT
Fix available in latest AspectJ Dev build, see AJ downloads page:

http://eclipse.org/aspectj/downloads.php