Bug 111915 - illegal change to pointcut declaration
Summary: illegal change to pointcut declaration
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-07 11:14 EDT by hesse CLA
Modified: 2012-04-03 15:52 EDT (History)
0 users

See Also:


Attachments
patch containing supplied testcase (2.86 KB, patch)
2005-10-11 08:45 EDT, Helen Beeken CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description hesse CLA 2005-10-07 11:14:18 EDT
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
Comment 1 Helen Beeken CLA 2005-10-10 04:31:42 EDT
Can you provide more information about what you were doing when you saw this?
The aspect you're writing etc.
Comment 2 hesse CLA 2005-10-11 08:05:47 EDT
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) {
    }

}
Comment 3 Helen Beeken CLA 2005-10-11 08:31:00 EDT
Thanks for the simplified testcase - I have been able to recreate the problem.

This is a compiler bug so reassigning to aspectj.
Comment 4 Helen Beeken CLA 2005-10-11 08:45:09 EDT
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.
Comment 5 Andrew Clement CLA 2005-10-20 10:12:41 EDT
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.

Comment 6 Andrew Clement CLA 2005-10-20 10:41:00 EDT
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
Comment 7 Andrew Clement CLA 2005-10-20 12:23:22 EDT
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
Comment 8 Andrew Clement CLA 2005-10-21 03:09:10 EDT
Fix checked in - waiting on build.
Comment 9 Andrew Clement CLA 2005-10-21 06:46:08 EDT
fix available.