Community
Participate
Working Groups
org.aspectj.weaver.BCException at org.aspectj.weaver.patterns.ReferencePointcut.concretize1(ReferencePointcut.java:306) at org.aspectj.weaver.patterns.Pointcut.concretize(Pointcut.java:229) at org.aspectj.weaver.patterns.ReferencePointcut.concretize1(ReferencePointcut.java:331) at org.aspectj.weaver.patterns.Pointcut.concretize(Pointcut.java:229) at org.aspectj.weaver.patterns.Pointcut.concretize(Pointcut.java:216) at org.aspectj.weaver.Advice.concretize(Advice.java:273) at org.aspectj.weaver.bcel.BcelAdvice.concretize(BcelAdvice.java:83) at org.aspectj.weaver.CrosscuttingMembers.addShadowMunger(CrosscuttingMembers.java:84) at org.aspectj.weaver.CrosscuttingMembers.addShadowMungers(CrosscuttingMembers.java:78) at org.aspectj.weaver.ResolvedType.collectCrosscuttingMembers(ResolvedType.java:462) at org.aspectj.weaver.CrosscuttingMembersSet.addOrReplaceAspect(CrosscuttingMembersSet.java:62) at org.aspectj.weaver.bcel.BcelWeaver.prepareForWeave(BcelWeaver.java:426) at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.weave(AjCompilerAdapter.java:283) at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.afterCompiling(AjCompilerAdapter.java:178) at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$afterReturning$org_aspectj_ajdt_internal_compiler_CompilerAdapter$2$f9cc9ca0(CompilerAdapter.aj:70) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:367) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:760) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:225) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:151) at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:122) at org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run(AspectJBuildManager.java:191) BCException thrown: illegal change to pointcut declaration: spike.np.CommandCase.handleCommand(BindingTypePattern(spike.np.OtherHandler$MyWorld, 0)) when batch building BuildConfig[/home/guido/workspace/.metadata/.plugins/org.eclipse.ajdt.core/np.generated.lst] #Files=11
Can you provide more information about what you were doing when you saw this? The aspect you're writing etc.
Here is a minimal sample: package aj; public class SomeClass { public void doSomething() { } public static void main(String... args) { new SomeClass().doSomething(); } } package aj; public aspect MyAspect { public interface MyWorld { } declare parents : SomeClass implements MyWorld; pointcut doSomethingInMyWorld(MyWorld myWorld) : execution(void SomeClass.doSomething()) && this(myWorld); void around(MyWorld myWorld) : doSomethingInMyWorld(myWorld) { System.out.println("this works"); } } package aj; public aspect DoesntCompile { public interface MyWorld { } declare parents : SomeClass implements MyWorld; pointcut doSomething(SomeClass someClass) : execution(void SomeClass.doSomething()) && this(someClass); pointcut doSomethingInMyWorld(MyWorld myWorld) : doSomething(myWorld); void around(MyWorld myWorld) : doSomethingInMyWorld(myWorld) { } }
Thanks for the simplified testcase - I have been able to recreate the problem. This is a compiler bug so reassigning to aspectj.
Created attachment 28111 [details] patch containing supplied testcase This patch is a patch to be applied to the tests project and contains the supplied testcase written to fit in with the aspectj testcase structure.
I've applied Helens patch then worked on reducing the test program as much as possible, this fails: class SomeClass { public void doSomething() { } } aspect DoesntCompile { declare parents : SomeClass implements Serializable; pointcut doSomething(SomeClass someClass) : execution(void SomeClass.doSomething()) && this(someClass); void around(Serializable myWorld) : doSomething(myWorld) { } } If I directly apply Serializable (i.e. not use declare parents) then it works. If I change the around advice to take a 'SomeClass' then it works.
Ok ... the problem here is the shadow munger is being concretized before the type munger that adds the parent has had a chance to take effect. The message 'illegal change to pointcut' is hopeless. Before producing the message it is actually looking at the pointcut and checking that what you are binding 'Serializable' is the same or a supertype of the value in the pointcut 'SomeClass'. What you are doing is allowed because all SomeClass' are Serializable - however, because the declare parents hasnt occurred yet, we don't know SomeClass is Serializable. Thats why it works if you either: a) hardcode SomeClass implements Serializable and dont use declare parents. b) change the advice to 'void around(SomeClass myWorld)' what on earth I can do about it ... hmmmmmmmmm
The actual problem of using the wrong type in the pointcut is checked in two places. 1. ReferencePointcut.resolveBindings produces something vaguely helpful like the message: incompatible type, expected SomeClass found BindingTypePattern(java.io.Serializable, 0) 2. ReferencePointcut.concretize1 produces the BCException: "illegal change to pointcut declaration: doSomething(BindingTypePattern(java.io.Serializable, 0))" I propose to remove the check for illegal change to pointcut decl as it: 1. is done too early 2. is duplicating something checked later 3. is an exception for something that should be an error 4. is extremely unhelpful
Fix checked in - waiting on build.
fix available.