Bug 34206 - before():execution(new(..)) does not throw NoAspectBoundException
Summary: before():execution(new(..)) does not throw NoAspectBoundException
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.2   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 37256 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-08 14:23 EST by Rafael Chaves CLA
Modified: 2004-01-14 10:30 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Chaves CLA 2003-03-08 14:23:07 EST
Aspectj Compiler 1.1beta4

In the "Aspect Instantiation and Advice" section in README-11.html, it is said
that an org.aspectj.lang.NoAspectBoundException will be thrown if a before
advice captures all constructors executions (including the aspect constructor).

      aspect Watchcall {
          pointcut myConstructor(): execution(new(..));

          before(): myConstructor() {
              System.err.println("Entering Constructor");
          }
      }

But adding a similar after advice to the same aspect will throw an obscure
NoClassDefError instead, which gives no clues about what the error is.
Comment 1 Rafael Chaves CLA 2003-03-08 14:45:43 EST
The modified aspect:

      aspect Watchcall {
          pointcut myConstructor(): execution(new(..));

          before(): myConstructor() {
              System.err.println("Entering Constructor");
          }

          after(): myConstructor() {
              System.err.println("Leaving Constructor");
          }
      }

The Java class (unchanged): 

      public class Client
      {
          public static void main(String[] args) {
              Client c = new Client();
          }
      }

The error stack trace:

Exception in thread "main" java.lang.NoClassDefFoundError
  at Client.<init>(Client.java:1)
  at Client.main(Client.java:4)
Comment 2 Jim Hugunin CLA 2003-03-11 14:45:59 EST
This behavior was easily verified.  Thanks for the simple test case.

I'm unsure what the correct resolution is.  The problem is a standard one
with after advice.  Because after advice will run even in the presence of
exceptions, it can lead to confusing behavior in the same way that try/finally
can.  See the FAQ entry on "When I run, I get a StackOverflowError (or a long 
stack trace or no output whatsoever)" for more information on a different 
manifestation of this same issue.

My recommendation in the short-term is to use after returning advice instead 
of after advice whenever possible to avoid these confusions.  For the
longer term this might merit discusion on the aspectj-dev list.
Comment 3 Jim Hugunin CLA 2003-05-06 14:20:56 EDT
*** Bug 37256 has been marked as a duplicate of this bug. ***
Comment 4 Jim Hugunin CLA 2004-01-14 10:30:38 EST
Finally fixed!

All exceptions that occur during the static intialization of a persingleton
aspect will be swallowed.  When using that aspect (via aspectOf()) 
a NoAspectBoundException will be thrown with the original exception
from the staitc initializer as the cause.