Bug 125062 - [generics] Generic, abstract aspects in Jar files
Summary: [generics] Generic, abstract aspects in Jar files
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0   Edit
Hardware: PC All
: P4 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-24 15:01 EST by david.pearce CLA
Modified: 2010-01-12 20:04 EST (History)
1 user (show)

See Also:


Attachments
Example code (657 bytes, application/octet-stream)
2006-01-24 15:03 EST, david.pearce CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description david.pearce CLA 2006-01-24 15:01:50 EST
Hi all,

I've encountered a slightly odd thing with generic abstract aspects
packaged in Jar files and I'm not sure whether it's a bug or just
incorrect syntax on my part.

The code in question is:

File AbstractAspect.aj:

> public abstract aspect AbstractAspect<T> { 
>  interface target<C> {
>   public C get();  
>  }
>
>  declare parents: T implements target; 
>
>  private int target<C>.aField;
>  public C target<C>.get() { return null; } }

File TestAspect.aj:

> aspect TestAspect extends AbstractAspect<Student> {}

 (details of the Student class are not important here)

There are two scenarios:

1) Compile AbstractAspect.aj, TestAspect.aj and Student.java statically
using ajc.  This works fine.

2) Compile AbstractAspect.aj separately and put into Jar file.  Then
compile TestAspect.aj and Student.java using ajc, with the Jar file on
the classpath.  This does not work.  The error message reported is:

> Inconsistent classfile encountered: The undefined type parameter C is
>   referenced from within AbstractAspect<T> public aspect TestAspect
>   extends AbstractAspect<Student> { } ...

I have observed that removing <C> from "target<C>.aField" and "Target<C> get()" makes it work.  I also tried using <D> instead of <C> in "target<C>.aField" and "Target<C> get()", but this didn't make any difference.  Curiously, though the error message still referred to the "C" (which was still present in the interface definition).  

Anyway, I have attached the complete example as a tarball.  

Cheers,

David Pearce
Comment 1 david.pearce CLA 2006-01-24 15:03:17 EST
Created attachment 33535 [details]
Example code
Comment 2 Andrew Clement CLA 2006-01-26 03:40:59 EST
first comment - dont use -noweave - it wont fix your problem but you shouldnt use it.  Reweavable is now the default and makes -noweave useless.
Comment 3 Andrew Clement CLA 2006-01-26 06:41:20 EST
ok, bit more investigation.  this bug is a real pain.

The problem is that the signature attached to the ITD refers to a type variable that exists on a member type, not on the enclosing type for the ITD.  When used as input to a subsequent weaving stage, the compiler creates a BinaryTypeBinding for the class and barfs when it can't sort out the signature and resolve the type variable.  With some magic, I can fix it in the case like this where the ITDs are on a member type within the same enclosing type.  What I think will cause me problems is ITDs like this that are made on an entirely separate type.  I seem to have two options:

1. attempt to resolve the type variable there and then by discovering the actual target (tricky - without processing the ITD, how do I know the target)
2. suppress the error for the ITD case like this and 'sort it out later' when the ITDs are processed.

option (2) seems nice.
Comment 4 Andrew Clement CLA 2008-06-11 12:05:17 EDT
really want to get to this, but 1.6.1 is already full of changes.
Comment 5 Andrew Clement CLA 2008-09-30 13:10:36 EDT
Similar workaround as done in bug 242797 would make this work - that was for generic ITDs, this is generic aspects.
Comment 6 Andrew Clement CLA 2010-01-12 20:04:00 EST
not doing any more on this in the short term, very few people hitting it