Bug 61537 - ajc adds a clinit() even when one is not needed
Summary: ajc adds a clinit() even when one is not needed
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: All other
: P3 blocker (vote)
Target Milestone: ---   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-09 12:52 EDT by Laurie Hendren CLA
Modified: 2004-05-10 13:59 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 Laurie Hendren CLA 2004-05-09 12:52:19 EDT
 
Comment 1 Laurie Hendren CLA 2004-05-09 12:53:17 EDT
public class Bug {
  // no static initializer in Bug
  // but the ajc compiler seems to create an empty one,  and then the advice
  // in the StaticInit aspect below matches this inserted empty clinit().
  // Is that the desired/expected behaviour?   I would have thought that
  // a clinit() method only appears in a class when there things to be put
  // in it?   Certainly javac does not create one.
}

class BugExt extends Bug {

  static int forceclinit = 13;

  public static void main(String args[])
   { BugExt b = new BugExt();
     System.out.println("Exiting main");
   }
}

aspect StaticInit{
  // this should never match
  before() : staticinitialization(Bug)
    { System.out.println("I am in the staticinitialization of Bug");
    }
}
Comment 2 Jim Hugunin CLA 2004-05-10 13:59:27 EDT
AspectJ defines a staticinitialization join point for the initialization of 
all classes.  The implementation of this join point uses the <clinit> method; 
however, that method isn't part of the AspectJ language spec (just like it 
isn't part of the JLS).  We believe that this definition of 
staticintialization is much more useful than one based on <clinit> because it 
is more stable in the face of small changes to the target code.