Community
Participate
Working Groups
Hi, I had defined a policy aspect to detect all System.out and System.err usages: public aspect DetectSystemOutErrorUsage { pointcut allSystemOutAndSystemErrAccesses(): (get(* System.out) || get(* System.err)) && !adviceexecution(); declare warning: allSystemOutAndSystemErrAccesses() && !within(myproject.test..*) // we don't care about test code && !within(myproject.log..*) // and the Log-package can log to whereever it wants to... >> && !withincode(* myproject.Test.create(..)) // the logger is only created in that method, so we must not log calls to this method : "Warning: use of System.out or System.err - consider logging instead!"; } This advice was working fine. But then I added the line marked with >> since it also complained about the create() method, in which I create the logger and if that fails I write a message to System.err about the failed logger creation. This should not yield a warning, so I wanted to exclude that from the pointcut. But If I add that to the aspect and then re-compile my project I get a null- pointer exception: Except from the eclipse log: ------------------------------------------------------- ... eclipse.buildId=I200405211200 java.version=1.4.2_03 java.vendor=Sun Microsystems Inc. BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US !ENTRY org.eclipse.ajdt.ui 4 0 May 28, 2004 12:35:58.259 !MESSAGE NullPointerException thrown: null !STACK 0 java.lang.NullPointerException at org.aspectj.weaver.patterns.SignaturePattern.matches (SignaturePattern.java:87) at org.aspectj.weaver.patterns.WithincodePointcut.match (WithincodePointcut.java:42) at org.aspectj.weaver.patterns.NotPointcut.match(NotPointcut.java:45) at org.aspectj.weaver.patterns.AndPointcut.match(AndPointcut.java:42) at org.aspectj.weaver.patterns.AndPointcut.match(AndPointcut.java:42) at org.aspectj.weaver.patterns.AndPointcut.match(AndPointcut.java:42) at org.aspectj.weaver.ShadowMunger.match(ShadowMunger.java:62) at org.aspectj.weaver.Checker.match(Checker.java:48) at org.aspectj.weaver.bcel.BcelClassWeaver.match(BcelClassWeaver.java:1121) at org.aspectj.weaver.bcel.BcelClassWeaver.matchInit(BcelClassWeaver.java:895) at org.aspectj.weaver.bcel.BcelClassWeaver.match(BcelClassWeaver.java:793) at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:343) at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:80) at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:724) at org.aspectj.weaver.bcel.BcelWeaver.weaveWithoutDump(BcelWeaver.java:689) at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:615) at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:563) at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.weave (AjCompilerAdapter.java:239) at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.afterCompiling (AjCompilerAdapter.java:114) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:376) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation (AjBuildManager.java:601) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild (AjBuildManager.java:160) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild (AjBuildManager.java:94) at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:108) at org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run (AspectJBuildManager.java:165) ------------------------------------------------------- This is using Eclipse 3.0M9 and AJDT 1.1.10. Regards, Michael
Hi Michael, Sorry I'm only just getting to this bug ! Is there any way you can supply me the myproject.Test class? As I can't recreate this with my own version. The problem is that one of the join points we attempt to match on in myproject.Test is returning null as its enclosing code signature (the enclosing code signature is what is compared with the withincode() supplied signature)
Fixed under bug 67774. Build now available containing the fix: BUILD COMPLETE - build.324 Date of build: 08/02/2004 15:14:37 Time to build: 100 minutes 0 seconds Last changed: 08/02/2004 14:43:47 Last log entry: Fix for Bugzilla Bug 67774 Nullpointer-exception in pointcuts using withincode() clause Latest good AspectJ jar available at: download.eclipse.org/technology/ajdt/dev/aspectj-DEVELOPMENT.jar
Fix released as part of AspectJ 1.2.1