Bug 156058

Summary: [generics] Reference to pointcut defined in generic aspect, within generic interface
Product: [Tools] AspectJ Reporter: Paulo Zenida <Paulo.Zenida>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2    
Version: DEVELOPMENT   
Target Milestone: 1.5.3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
failing testcase aclement: iplog+

Description Paulo Zenida CLA 2006-09-03 10:16:33 EDT
I had the latest release version of the AspectJ compiler, 1.5.2RC1 and I had the following problem. I even tried the latest AspectJ compiler version: 1.4.1.200609011748 for Eclipse 3.2 and I still found this strange behaviour while using aspects within interfaces, when those interfaces get generics. For example:

public interface MyInterface1<T> {

  public abstract static aspect MyAspect1<T> {

    public void foo() {
      System.out.println("Fooooooo");
    }

    public final pointcut myPointcutInInterface() :                         
      call(* *..*.*(..));
  }
}

public aspect MyAspect implements MyInterface1<MyClass> {

  before() :
    MyAspect1<MyClass>.myPointcutInInterface() &&
    !within(MyAspect<MyClass>) {
      System.out.println("Before executing!");
    }
}

Results in an exception thrown by the AspectJ compiler:

java.lang.IllegalStateException
at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:42)
at
org.aspectj.weaver.patterns.WildTypePattern.resolveParameterizedType(WildTypePattern.java:790)
at
org.aspectj.weaver.patterns.WildTypePattern.resolveBindingsForExactType(WildTypePattern.java:732)
at
org.aspectj.weaver.patterns.WildTypePattern.resolveBindingsFromFullyQualifiedTypeName(WildTypePattern.java:699)
at org.aspectj.weaver.patterns.WildTypePattern.resolveBindings(WildTypePattern.java:623)
at org.aspectj.weaver.patterns.TypePattern.resolveExactType(TypePattern.java:190)
at
org.aspectj.weaver.patterns.ReferencePointcut.resolveBindings(ReferencePointcut.java:130)
at org.aspectj.weaver.patterns.AndPointcut.resolveBindings(AndPointcut.java:74)
at org.aspectj.weaver.patterns.Pointcut.resolve(Pointcut.java:196)
at
org.aspectj.ajdt.internal.compiler.ast.PointcutDesignator.finishResolveTypes(PointcutDesignator.java:84)
at
org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration.resolveStatements(AdviceDeclaration.java:119)
at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:400)
at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1088)
at
org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration.resolve(AspectDeclaration.java:116)
at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1137)
at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:305)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:519)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)
at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:887)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:271)
at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.incrementalBuild(AjBuildManager.java:170)
at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:117)
at
org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run(AspectJBuildManager.java:191)

IllegalStateException thrown: Expecting raw type

Without the generics, the program works just fine. I don't understand what is the problem. Can anyone help me, please? Thanks in advance.


Best regards,


Paulo Zenida
Comment 1 Matthew Webster CLA 2006-09-04 12:24:19 EDT
I can reproduce the problem with the (excellent) testcase. Moving MyAspect1<T> into it's own source file avoids the exception which makes me think it might be related to Bug 153490 "IllegalStateException thrown: ...". Will need to do some more investigation.
Comment 2 Helen Beeken CLA 2006-09-05 03:54:37 EDT
From the error message "IllegalStateException thrown: Expecting raw type" it is possible this bug is related to bug 152848.
Comment 3 Helen Beeken CLA 2006-09-06 05:53:27 EDT
After some initial investigation I don't believe this bug is related to bug 152848. The problem here is to do with being an inner type.

Converting the supplied testcode into a testcase that fits within the testsuite, the latest code from HEAD returns the following message:

Expecting raw type, not: MyInterface$MyAspect1<>

What's happening is that we're entering TypeFactory.createParameterizedType(..) with a ResolvedType that isn't a generic type (which is why we go on to find the generic type) but is a parameterized type. Therefore, the test isRawType() returns false and we blow up with the IllegalStateException.
Comment 4 Helen Beeken CLA 2006-09-06 05:56:02 EDT
Created attachment 49475 [details]
failing testcase

Apply this patch to the tests project.
Comment 5 Andrew Clement CLA 2006-09-13 08:50:24 EDT
I think I can say with some confidence that we have *no* tests for generic inner aspects of generic types.  That program looks scary to me but it is highlighting a few bugs.  Behind the failures there are actually problems with the pointcut: within() can't take a parameterized type - there would be no difference between within(Foo<String>) and within(Foo<Integer>) - there is only one Foo.

So I will working on fixing this bug but I have to warn you that this could well be a buggy area and some bugs may not get fast turnaround, since I think I can see some infrastructure missing from our implementation that needs writing to handle these situations.
Comment 6 Andrew Clement CLA 2006-10-06 11:46:38 EDT
alright, i have fixed this.  Or rather I've selotaped over this particularly bug.  It is still not a well tested area and I've added just two tests for this scenario - so I expect to see related bugs in the future...
Comment 7 Andrew Clement CLA 2006-10-12 12:37:38 EDT
fixes are available in aj dev builds