Community
Participate
Working Groups
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
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.
From the error message "IllegalStateException thrown: Expecting raw type" it is possible this bug is related to bug 152848.
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.
Created attachment 49475 [details] failing testcase Apply this patch to the tests project.
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.
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...
fixes are available in aj dev builds