Bug 103740 - Compiler failure on @annotation
Summary: Compiler failure on @annotation
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.0 M4   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-13 19:09 EDT by Ron Bodkin CLA
Modified: 2005-09-12 12:20 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ron Bodkin CLA 2005-07-13 19:09:31 EDT
I'm using the ajc embedded in the latest dev build of AJDT (build 
20050713163417)

This small example illustrates the problem:
public abstract aspect AbstractRequestMonitor {

    public pointcut requestExecution(RequestContext requestContext) :
        execution(* RequestContext.execute(..)) && this(requestContext);

    public abstract class RequestContext {
        public abstract Object execute();
    }
    
    after(RequestContext requestContext) throwing (Throwable t) : 
requestExecution(requestContext) {
    }
    
}

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface AroundAdvice {

}

public aspect ErrorHandling {

    declare soft: Exception: !@annotation(AroundAdvice) && !withincode(* *
(..));
    
    Object around() : adviceexecution() && !@annotation(AroundAdvice) {
        try {
            return proceed();
        } catch (Exception e) {
            return null;
        }
    }

}

Here's the stack trace I get:

org.aspectj.weaver.BCException: bad
	at org.aspectj.weaver.bcel.BcelRenderer.visit(BcelRenderer.java:228)
	at org.aspectj.weaver.ast.Literal.accept(Literal.java:29)
	at org.aspectj.weaver.bcel.BcelRenderer.recur(BcelRenderer.java:151)
	at org.aspectj.weaver.bcel.BcelRenderer.renderTest
(BcelRenderer.java:117)
	at org.aspectj.weaver.bcel.BcelAdvice.getTestInstructions
(BcelAdvice.java:445)
	at org.aspectj.weaver.bcel.BcelShadow.weaveAroundClosure
(BcelShadow.java:2585)
	at org.aspectj.weaver.bcel.BcelAdvice.implementOn(BcelAdvice.java:182)
	at org.aspectj.weaver.Shadow.implementMungers(Shadow.java:480)
	at org.aspectj.weaver.Shadow.implement(Shadow.java:358)
	at org.aspectj.weaver.bcel.BcelClassWeaver.implement
(BcelClassWeaver.java:1703)
	at org.aspectj.weaver.bcel.BcelClassWeaver.weave
(BcelClassWeaver.java:389)
	at org.aspectj.weaver.bcel.BcelClassWeaver.weave
(BcelClassWeaver.java:94)
	at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1362)
	at org.aspectj.weaver.bcel.BcelWeaver.weaveWithoutDump
(BcelWeaver.java:1327)
	at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify
(BcelWeaver.java:1106)
	at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:981)
	at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.weave
(AjCompilerAdapter.java:286)
	at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.afterCompiling
(AjCompilerAdapter.java:165)
	at 
org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$afterReturning$org_aspec
tj_ajdt_internal_compiler_CompilerAdapter$2$f9cc9ca0(CompilerAdapter.aj:70)
	at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile
(Compiler.java:368)
	at 
org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation
(AjBuildManager.java:727)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild
(AjBuildManager.java:206)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild
(AjBuildManager.java:140)
	at org.aspectj.ajde.internal.CompilerAdapter.compile
(CompilerAdapter.java:121)
	at org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run
(AspectJBuildManager.java:191)
Comment 1 Adrian Colyer CLA 2005-07-14 03:29:35 EDT
One for Andy... ;)
Comment 2 Adrian Colyer CLA 2005-08-26 11:53:11 EDT
for M4
Comment 3 Andrew Clement CLA 2005-09-12 06:44:10 EDT
Heres my reduced program that also fails:

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface AroundAdvice { }

aspect ErrorHandling {
  before(): !@annotation(AroundAdvice) { }
}

the '!' is causing the problem.
Comment 4 Andrew Clement CLA 2005-09-12 09:41:33 EDT
Fix checked in.  We were always returning 'Literal.TRUE' from
findResidueInternal for the annotation pointcut type which became a
'Literal.FALSE' due to the NOT.  We always blow up if attempting to visit
(generate) a test that is Literal.FALSE (since we shouldn't have gotten to this
point claiming it was ever a match).  

The fix is to make findResidueInternal() return either TRUE or FALSE depending
on whether the shadow actually matched the pointcut.  In the case where a join
point does *not* have the annotation, it will now return FALSE, which will
become TRUE due to the ! and this is a valid test.

waiting on build before closing bug.
Comment 5 Andrew Clement CLA 2005-09-12 12:20:52 EDT
Fix available now.