Bug 292239 - Method in pointcut not advised by after throwing()
Summary: Method in pointcut not advised by after throwing()
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.5   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 1.6.12   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 341078
  Show dependency tree
 
Reported: 2009-10-14 07:16 EDT by Steve Powell CLA
Modified: 2011-03-28 05:45 EDT (History)
2 users (show)

See Also:


Attachments
Amalgam of files to test aspectj advice. (2.15 KB, text/plain)
2009-10-14 07:16 EDT, Steve Powell CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Powell CLA 2009-10-14 07:16:00 EDT
Created attachment 149513 [details]
Amalgam of files to test aspectj advice.

after(Object o) throwing(ExceptionType e) ... { ... }

on a pointcut that matches methods with no throws clauses

will not advise those methods when the ExceptionType is a checked exception. 
This, I believe, is an optimisation.

However, it is perfectly possible that ExecptionType is checked but subclasses
of ExceptionType are not.

The prototypical example, is Exception.  If throwing(Exception e) is part of
the advice, then methods that do not declare throws types are NOT advised, even
though they can validly throw (for example) RuntimeException. The
RuntimeExceptions are therefore not caught by the after advice.

The workaround is to specify throwing(Throwable t) and for the advice to filter
out Exception exceptions. Since Throwable is not checked, this advises all
methods whether they declare throws or not.

I expect the after(Object o) throwing(ExceptionType e) {} to advise all methods
in the pointcut that may possibly issue an exception that would be caught by
catch(ExceptionType e) -- this includes subclasses of ExceptionType which may
not be checked.

Example attached.

[I do not think this problem is operating system specific.]
Comment 1 Andrew Clement CLA 2009-10-14 11:56:36 EDT
for 1.6.7 find some time to work out why it is like this...
Comment 2 Steve Powell CLA 2010-07-06 10:00:30 EDT
(In reply to comment #1)
> for 1.6.7 find some time to work out why it is like this...

I see we've drifted out to 1.6.10.
Comment 3 Steve Powell CLA 2010-09-09 08:06:40 EDT
Nights are beginning to draw in....
Comment 4 Steve Powell CLA 2011-01-19 10:21:56 EST
Hi Andy, 
long time no comment....  :-)

Hey, I've an idea, why not document this behaviour (carefully) and close this bug as 'working as designed'?
Comment 5 Andrew Clement CLA 2011-03-23 12:31:39 EDT
fixed !!

I kept debating whether to change this behaviour or not.  The change may impact some users exploiting the way it has been working up to now.  However, I made the change and none of the AspectJ tests were affected.  I was also struck particularly by the comment:

> I expect the after(Object o) throwing(ExceptionType e) {} to advise all methods
> in the pointcut that may possibly issue an exception that would be caught by
> catch(ExceptionType e)

I think that is right.  So I've committed the change.
Comment 6 Steve Powell CLA 2011-03-28 05:43:58 EDT
(In reply to comment #5)
Thank you!  We will now raise a bug in Virgo to track this change and when we upgrade aspectj we can simplify our code.