Bug 114875 - @Pointcut - throws java.lang.NullPointerException
Summary: @Pointcut - throws java.lang.NullPointerException
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 114876 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-11-03 00:25 EST by Mohan Radhakrishnan CLA
Modified: 2005-11-21 06:29 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mohan Radhakrishnan CLA 2005-11-03 00:25:18 EST
Eclipse 3.1
AJDT 1.3.0.20051102174241

package com.aspectj.test;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public abstract class Base {

    @Pointcut                                     -->Seems to be the problem
    abstract void method();
	

    public static void main(String args[]){
    }
}

package com.aspectj.test;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class Sub extends Base{

    @Pointcut( "execution(* com.aspectj.test.Base.main(..))" )
    void method(){};

    @Before("method()")
    public void test(){
		
    }
}


The code above shows

java.lang.NullPointerException
	at org.aspectj.weaver.patterns.BasicTokenSource.makeTokenSource
(BasicTokenSource.java:84)
	at org.aspectj.weaver.patterns.PatternParser.<init>
(PatternParser.java:1373)
	at 
org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVisitor.conv
ertToPointcutDeclaration(ValidateAtAspectJAnnotationsVisitor.java:493)
	at 
org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVisitor.visi
t(ValidateAtAspectJAnnotationsVisitor.java:188)
	at 
org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse
(MethodDeclaration.java:185)
	at 
org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse
(TypeDeclaration.java:1183)
	at 
org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.tr
averse(CompilationUnitDeclaration.java:339)
	at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.beforeAnalysing
(AjCompilerAdapter.java:154)
	at 
org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$before$org_aspectj_ajdt_
internal_compiler_CompilerAdapter$7$db78446d(CompilerAdapter.aj:101)
	at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process
(Compiler.java:517)
	at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile
(Compiler.java:329)
	at 
org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation
(AjBuildManager.java:759)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild
(AjBuildManager.java:225)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild
(AjBuildManager.java:180)
	at 
org.aspectj.ajdt.internal.core.builder.AjBuildManager.incrementalBuild
(AjBuildManager.java:158)
	at org.aspectj.ajde.internal.CompilerAdapter.compile
(CompilerAdapter.java:117)
	at org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run
(AspectJBuildManager.java:191)


The syntax @Pointcut("") is shown as error too. If this is not a bug then a 
proper message instead of an exception is helpful.
Comment 1 Andrew Clement CLA 2005-11-03 03:24:03 EST
*** Bug 114876 has been marked as a duplicate of this bug. ***
Comment 2 Andrew Clement CLA 2005-11-03 03:24:25 EST
needs fixing for RC1
Comment 3 Alexandre Vasseur CLA 2005-11-03 04:10:37 EST
odd
the line ValidateAtAspectJAnnotationsVisitor.java:493 is meaningless
this is also covered by the suite (ConcreteAtAspect.java)

I suspect that ajdt.core is not properly mirroring what is in the source.
Andy, you can probably understand what 's going on there - unless the answer is
simply that AJ in AJDT is older than AJ last good known snapshot.

Mohan you can try using a recent AJ build and ajc (outside of AJDT)
Comment 4 Andrew Clement CLA 2005-11-03 04:19:47 EST
AJDT definetly has an older AJ in it (from a week or so ago).  I've tried this
program with the latest AJ and it doesn't fail for me.

Line 493 said this:

Pointcut pc = new PatternParser(pointcutExpression,context).parsePointcut();

in version 1.12 of the Validateblahblahblah class. and given that alex's checkin
comment is 'ajdtcore for abstract @Pointcut' for 1.13 then I'm assuming the fix
went into 1.13 and hasn't surfaced in an AJDT yet.
Comment 5 Mohan Radhakrishnan CLA 2005-11-03 07:51:18 EST
I tried the latest aj dev. build.

Now my code is

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public abstract class Base {

	@Pointcut
    abstract void method();
	

	public static void main(String args[]){
	}
}

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class Sub extends Base{

	@Pointcut( "execution(* com.aspectj.test.Base.main(..))" )
    void method(){};

	@Before("method()")
    public void test(){
		//System.out.println("Advised by "+this);

	}
}

When I compile Base.java it works. When I compile Sub.java I see this 
exception.

java.lang.NullPointerException
        at 
org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi
sitor.validateAspectDeclaration(ValidateAtAspectJAnnotationsVisitor.java:243)
        at 
org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi
sitor.checkTypeDeclaration(ValidateAtAspectJAnnotationsVisitor.java:119)
        at 
org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi
sitor.visit(ValidateAtAspectJAnnotationsVisitor.java:107)
        at 
org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.tra
verse(TypeDeclaration.java:1145)
        at 
org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDecl
aration.traverse(CompilationUnitDeclaration.java:339)
        at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.beforeAnalysing
(
AjCompilerAdapter.java:154)
        at 
org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$before$org_asp
ectj_ajdt_internal_compiler_CompilerAdapter$7$db78446d(CompilerAdapter.aj:101)
        at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process
(Compil
er.java:517)
        at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile
(Compil
er.java:329)
        at 
org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilat
ion(AjBuildManager.java:759)
        at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild
(AjBuild
Manager.java:225)
        at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild
(AjBu
ildManager.java:151)
        at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
        at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
        at org.aspectj.tools.ajc.Main.run(Main.java:326)
        at org.aspectj.tools.ajc.Main.runMain(Main.java:240)
        at org.aspectj.tools.ajc.Main.main(Main.java:83)
Comment 6 Alexandre Vasseur CLA 2005-11-03 10:17:21 EST
fails when looking for parent type?

			if (parentBinding instanceof SourceTypeBinding) {
				SourceTypeBinding parentSTB = (SourceTypeBinding) parentBinding;
				TypeDeclaration parentDecl = parentSTB.scope.referenceContext; //!!!!!!!!
NPE here
				if (isAspect(parentDecl) && !Modifier.isAbstract(parentDecl.modifiers)) {
				
typeDecl.scope.problemReporter().signalError(typeDecl.sourceStart,typeDecl.sourceEnd,"cannot
extend a concrete aspect");
				}			
			}
Comment 7 Alexandre Vasseur CLA 2005-11-07 05:50:19 EST
cannot reproduce in AJC from CVS head
see test - in tests/java5/ataspectj.../bugs/AbstractAspectNPE[Child|Parent].java

Mohan, please advise
Comment 8 Mohan Radhakrishnan CLA 2005-11-08 05:24:37 EST
I am using the Last Known Good developer build.
Comment 9 Andrew Clement CLA 2005-11-21 03:50:20 EST
I've recreated this. fixing it now.
Comment 10 Andrew Clement CLA 2005-11-21 04:23:57 EST
this happens during incremental compilation.  We attempt to look at the scope of an object we believe is a SourceTypeBinding.  In the AJ world a BinaryTypeBinding is a subtype of SourceTypeBinding (for our 'binary source' support) - and if we don't allow for this case we end up working with a null scope.

fix checked in, waiting on build
Comment 11 Andrew Clement CLA 2005-11-21 06:29:34 EST
fix available in latest AJ dev build.