Community
Participate
Working Groups
According to Jim Hugunin. "The bug has to do with a situation where code in a class can run before that class's static initializer has completed. We've designed the JoinPoint.StaticPart object initialization code so that it is robust to most such issues, but we've apparently missed a case." I am using AspectJ 1.1rc1 public aspect BaseAspect { pointcut methodExec(): execution(* *..*(..)) && !within(BaseAspect); after () returning: methodExec() { thisJoinPoint.getSignature(); } } public abstract class Expression { public static Expression EMPTYSTRING = new Operator(); } public class Operator extends Expression { public Operator() { initOperands(); // the bug goes away if you remove this call. } public void initOperands() { } public static void main (String [] args) { Operator t = new Operator(); } } That stack dump Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.NullPointerException at BaseAspect.ajc$afterReturning$BaseAspect$df(BaseAspect.java:10) at Operator.initOperands(Operator.java:8) at Operator.<init>(Operator.java:4) at Expression.<clinit>(Expression.java:2)
I can't figure out any way to avoid this error that doesn't add runtime overhead to any advice that uses thisJoinPointStaticPart. This error is so unusual that I'm doubtful it's acceptable to penalize all advice for this odd case. Note that any program which would show this bug already has the surprising behavior that a properly initialized static final field may be seen to be null. i.e. if you add to Operator the line: static final Object name = "name"; And then add to initOperands() the following: System.out.println(name); You'll see that even though name is a static final under this bizarre initialization situation it can be seen to be null. This bug is waiting for a patch to be submitted showing how it can be prevented without adding performance overhead to all advice that uses thisJoinPointStaticPart.
We're not going to get to this in AJ 1.5.0. Marking as "LATER" for consideration in 1.5.1 and future release planning. The bug has not been hit by any other user in the last 2.5 years, so low priority.
LATER/REMIND bugs are being automatically reopened as P5 because the LATER and REMIND resolutions are deprecated.