Bug 36810 - Null static part of thisJoinPoint
Summary: Null static part of thisJoinPoint
Status: REOPENED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords: info
Depends on:
Blocks:
 
Reported: 2003-04-23 14:48 EDT by Mohamed Mansour CLA
Modified: 2009-08-30 02:50 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 Mohamed Mansour CLA 2003-04-23 14:48:44 EDT
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)
Comment 1 Jim Hugunin CLA 2004-01-27 19:12:04 EST
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.
Comment 2 Adrian Colyer CLA 2005-08-26 10:59:56 EDT
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.
Comment 3 Eclipse Webmaster CLA 2009-08-30 02:50:35 EDT
LATER/REMIND bugs are being automatically reopened as P5 because the LATER and REMIND resolutions are deprecated.