Bug 44587 - Erroneous exception conversion
Summary: Erroneous exception conversion
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.1   Edit
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: 1.2   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-09 13:58 EDT by Ron Bodkin CLA
Modified: 2004-03-19 09:52 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ron Bodkin CLA 2003-10-09 13:58:19 EDT
The following code results in an incorrect exception NoClassDefFoundError 
being thrown (and without a stack trace). Here is the output when running 
after compiling with AspectJ from head (and AspectJ 1.1.1):
C:\devel\test\excHandling\interType>java client.Main
Exception in thread "main" java.lang.NoClassDefFoundError
        at client.Main.main(Main.java:6)

AspectJ 1.0.6 doesn't exhibit this problem; it produces the following output:
C:\devel\test\excHandling\interType>java client.Main
Exception in thread "main" java.lang.ExceptionInInitializerError
        at client.Main.main(Main.java;client/ExceptionHandling.java
[1k];library/
LogManager.java[2k]:1004)
Caused by: java.lang.RuntimeException: evil
        at client.ExceptionHandling.doGetLogger_library_LogManager
(ExceptionHand
ling.java;library/LogManager.java[1k]:1009)
        at client.ExceptionHandling.<init>
(ExceptionHandling.java;library/LogMan
ager.java[1k]:1006)
        at client.ExceptionHandling.<clinit>
(ExceptionHandling.java;library/LogM
anager.java[1k]:3)
        ... 1 more

This example is probably related to bug #44586.
If you change the after throwing advice in client/ExceptionHandling.java to 
remove the execution OR initialization part, you get similar the following 
output to the AspectJ 1.0.6 case; the exception isn't swallowed.

Here is our test code:
package client;

public aspect ExceptionHandling {
    after() throwing (Throwable t) : execution(* Main.*(..)) || initialization
(Main.new(..)) {
	System.err.println("exception thrown at "+thisJoinPointStaticPart);
	t.printStackTrace(System.err);
    }
}
---
package client;

import library.Loggable;

public aspect LogManager {
    declare parents: client..* implements Loggable;
}
---
package client;

public class Main {
    public static void main(String args[]) {
	new Main();
    }
}
---
package library;

import java.util.logging.Logger;

public aspect LogManager {
    private Logger Loggable.logger = doGetLogger();
    public Logger Loggable.getLogger() { return logger; }
    private Logger Loggable.doGetLogger() {
	throw new RuntimeException("evil");
	//return Logger.getLogger("main");
    }
}
---
package library;

public interface Loggable {}
Comment 1 Jim Hugunin CLA 2004-01-14 10:30:21 EST
Fixed in tree.

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.
Comment 2 Adrian Colyer CLA 2004-03-19 09:52:01 EST
updating target flag to indicate inclusion in 1.2 release.