Bug 110307 - Can't provide default implementation via ITD for generic method in interface.
Summary: Can't provide default implementation via ITD for generic method in interface.
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-22 08:29 EDT by Andrew Clement CLA
Modified: 2005-10-20 10:30 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2005-09-22 08:29:43 EDT
From mailing list...
I think we should get an error 'Type T cant be found' and it should be possible
to provide a default implementation for a generic method specified on an interface.

====

I have an error in ExtendProduct aspect on method getTarget(). I give
the code below
Does somebody have an idea?
This error is :
can't override Link<Revision> AssociationSource<Revision>.getTarget()
with Link<T> AssociationSource.getTarget() return types don't match

Moreover, one advice having a generic type of return gives a similar error.
Was this feature implemented in the last version of apectj.
Thanks.
Stéphane Chomat.

This sample code :

public class Link<T> extends SoftReference {

   @SuppressWarnings("unchecked")
   Link(List<T> endPoints) {
       super(endPoints);
   }

   @SuppressWarnings("unchecked")
   public List<T> getEndPoints() {
       return (List<T>)get();
   }

}

interface AssociationSource<T> {

       public Link<T> getTarget();

       public void setTarget(Link<T> _target);

}

aspect ExtendProduct {
       Link<T> AssociationSource._target = null;

       public Link<T> AssociationSource.getTarget() {
           return _target;
       }

       public void AssociationSource.setTarget(Link<T> _target) {
           this._target = _target;
       }

       declare parents : ProductType implements
AssociationSource<Product>;
       declare parents : Product     implements AssociationSource<Branch>;
       declare parents : Branch      implements
AssociationSource<Revision>;
}
Comment 1 Andrew Clement CLA 2005-09-26 10:30:11 EDT
Ok, i've started on this bug - on my way to looking at the real problem I'm
failing with an NPE for this program:

import java.lang.annotation.*;
import java.lang.ref.*;

class Product{}
class ProductType{}

interface AssociationSource<T> {

  Link<T> getTarget();

  void setTarget(Link<T> _target);

}
aspect ExtendProduct {
       Link<T> AssociationSource._target = null;

       public Link<T> AssociationSource.getTarget() {
           return _target;
       }

       public void AssociationSource.setTarget(Link<T> _target) {
           this._target = _target;
       }

       declare parents : ProductType implements AssociationSource<Product>;
       declare parents : Product     implements AssociationSource<Branch>;
       declare parents : Branch      implements AssociationSource<Revision>;
}

class Link<T> extends SoftReference {

   @SuppressWarnings("unchecked")
   Link(List<T> endPoints) {
       super(endPoints);
   }

   @SuppressWarnings("unchecked")
   public List<T> getEndPoints() {
       return (List<T>)get();
   }

}

The types 'Branch' and 'Revision' are missing from the program, but that
shouldnt cause: 

java.lang.NullPointerException
        at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.addPare
nt(AjLookupEnvironment.java:711)
        at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.doDecla
reParents(AjLookupEnvironment.java:576)
        at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.weaveIn
terTypeDeclarations(AjLookupEnvironment.java:462)
        at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.weaveIn
tertypes(AjLookupEnvironment.java:255)
        at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.complet
eTypeBindings(AjLookupEnvironment.java:179)
        at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.beginToCompile
(Compiler.java:301)
        at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compil
er.java:315)
        at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilat
ion(AjBuildManager.java:737)
        at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuild
Manager.java:208)
        at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBu
ildManager.java:142)
        at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
        at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
        at org.aspectj.tools.ajc.Main.run(Main.java:324)
        at org.aspectj.tools.ajc.Main.runMain(Main.java:238)
        at org.aspectj.tools.ajc.Main.main(Main.java:82)
Comment 2 Andrew Clement CLA 2005-09-26 10:35:47 EDT
I've not fixed that NPE yet, but the complete program is this:

import java.util.*;
import java.lang.annotation.*;
import java.lang.ref.*;

class Product{}
class ProductType{}
class Branch {}
class Revision {}

interface AssociationSource<T> {

  Link<T> getTarget();

  void setTarget(Link<T> _target);

}
aspect ExtendProduct {
       Link<T> AssociationSource<T>._target = null;

       public Link<T> AssociationSource<T>.getTarget() {
           return _target;
       }

       public void AssociationSource<T>.setTarget(Link<T> _target) {
           this._target = _target;
       }

       declare parents : ProductType implements AssociationSource<Product>;
       declare parents : Product     implements AssociationSource<Branch>;
       declare parents : Branch      implements AssociationSource<Revision>;
}

class Link<T> extends SoftReference {

   @SuppressWarnings("unchecked")
   Link(List<T> endPoints) {
       super(endPoints);
   }

   @SuppressWarnings("unchecked")
   public List<T> getEndPoints() {
       return (List<T>)get();
   }

}

and this fails with:

K:\ws\aspectj_ws3\tests\bugs150\pr110307>ajc -1.5 Problem2.java
K:\ws\aspectj_ws3\tests\bugs150\pr110307\Problem2.java:1 [error] can't override
Link<Product> AssociationSource<Product>.getTarget() with Link<T> AssociationSou
rce.getTarget() return types don't match
(no source information available)
K:\ws\aspectj_ws3\tests\bugs150\pr110307\Problem2.java:1 [error] can't override
Link<Branch> AssociationSource<Branch>.getTarget() with Link<T> AssociationSourc
e.getTarget() return types don't match
(no source information available)
K:\ws\aspectj_ws3\tests\bugs150\pr110307\Problem2.java:1 [error] can't override
Link<Revision> AssociationSource<Revision>.getTarget() with Link<T> AssociationS
ource.getTarget() return types don't match
(no source information available)
K:\ws\aspectj_ws3\tests\bugs150\pr110307\Problem2.java:20 [error] can't override
 Link<Revision> AssociationSource<Revision>.getTarget() with Link<T> Association
Source.getTarget() return types don't match
public Link<T> AssociationSource.getTarget() {
                                 ^^^
K:\ws\aspectj_ws3\tests\bugs150\pr110307\Problem2.java:20 [error] can't override
 Link<Branch> AssociationSource<Branch>.getTarget() with Link<T> AssociationSour
ce.getTarget() return types don't match
public Link<T> AssociationSource.getTarget() {
                                 ^^^
K:\ws\aspectj_ws3\tests\bugs150\pr110307\Problem2.java:20 [error] can't override
 Link<Product> AssociationSource<Product>.getTarget() with Link<T> AssociationSo
urce.getTarget() return types don't match
public Link<T> AssociationSource.getTarget() {
                                 ^^^

6 errors
Comment 3 Andrew Clement CLA 2005-09-29 06:17:06 EDT
The NPE is fixed.

The other problem occurs because we don't parameterize ITDs for application to a
particular type.  E.g.

List<T> I<T>.foo() { return null; }

when a type A that looks like this:

class A implements I<String> {}

has matched, should be targetted with a parameterized form of the ITD:

List<String> I.foo() { return null; }

i'm in progress of fixing this.
Comment 4 Andrew Clement CLA 2005-10-17 08:58:36 EDT
I've created multiple cases for this problem, they are in CVS and I'm working
through them - the full description of what I am doing is going into bug 112105
Comment 5 Andrew Clement CLA 2005-10-18 04:25:05 EDT
Fixed all interesting cases covered by this bug ... bug 112105 will now continue
the ITD generics work.  Closing this one when build is through...
Comment 6 Andrew Clement CLA 2005-10-20 10:30:26 EDT
yey!  fix available.