Bug 206513

Summary: proceed() cannot be cast within parameterized Aspect
Product: [Tools] AspectJ Reporter: George Heineman <heineman>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: aclement
Version: 1.5.0   
Target Milestone: 1.6.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description George Heineman CLA 2007-10-16 14:42:50 EDT
Consider the following aspect:

public abstract aspect Another<V> {

	public abstract pointcut toBeFilledIn();

	Object around() : toBeFilledIn() {
		V v = (V) proceed();
		return v;
	}
}

This snippet is a reduced part of a solution which intended to cache values of a computation instead of calculating each time (i.e., memoization).

Here, the abstract pointcut would be made concrete and thus the type of proceed() could be known and a concrete aspect could be written to extend this abstract aspect.

The above code shows the following error trace. The problem boils down to the (V) cast of proceed().

Internal compiler error java.lang.NullPointerException at 
 org.aspectj.org.eclipse.jdt.internal.compiler.problem.ProblemReporter.unsafeCast(ProblemReporter.java:5302) at 
 org.aspectj.org.eclipse.jdt.internal.compiler.ast.CastExpression.resolveType(CastExpression.java:386) at 
 org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:199) at 
 org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:422) at 
 org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:178) at 
 org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration.resolveStatements(AdviceDeclaration.java:135) 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(CompilationUnit Declaration.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:
 974) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:262) at 
 org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:214) at 
 org.aspectj.ajdt.internal.core.builder.AjBuildManager.incrementalBuild(AjBuildManager.java:185) 
 at org.aspectj.ajde.core.internal.AjdeCoreBuildManager.doBuild(AjdeCoreBuildManager.java:88) 
 at org.aspectj.ajde.core.AjCompiler.build(AjCompiler.java:96) at 
 org.eclipse.ajdt.core.builder.AJBuilder.build(AJBuilder.java:198) at 
 org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:624) at 
 org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at 
 org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:166) at 
 org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:197) at 
 org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:246) at 
 org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at 
 org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:249) at 
 org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:302) at 
 org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:334) at 
 org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:137) at 
 org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235) at 
 org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

The "workaround" is to *not* parameterize the aspect, but long-term this solution will run into problems because of the inability to type the proceed() return.

Platform: Eclipse Europa on Windows PC. AJDT 1.5.0.200706070619 and Jre1.5.0_12 Java runtime.

-- george
Comment 1 Andrew Clement CLA 2008-06-11 17:58:45 EDT
After checking the code used to fail to compile in the 1.5 stream, the supplied code compiles fine under AspectJ1.6.0 (and later)