aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs/ErroneousExceptionConversion.java
blob: 13db17a1841b18944ad2bbb95025a2a27a2a9d98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// pr 44587
import org.aspectj.testing.Tester;
import org.aspectj.lang.NoAspectBoundException;
public class ErroneousExceptionConversion {
	
	public static void main(String[] args) {
		try {
			new ErroneousExceptionConversion();
			Tester.checkFailed("Wanted an exception in initializer error");
		} catch (NoAspectBoundException nabEx) {
			// good
			// check nabEx.getCause instanceof RuntimeException and has explanation "boom..."
			Throwable cause = nabEx.getCause();
			if (!(cause instanceof RuntimeException)) {
				Tester.checkFailed("Should have a RuntimeException as cause");
			}
		} catch(Throwable t) {
			Tester.checkFailed("Wanted an ExceptionInInitializerError but got " + t);
		}
	}
	
			
}

aspect A {
	
	int ErroneousExceptionConversion.someField = throwIt();
	
	public static int throwIt() {
		throw new RuntimeException("Exception during aspect initialization");
	}
	
	public A() {
		System.err.println("boom in 5...");
		throw new RuntimeException("boom");
	}
	
	// if I change this to execution the test passes...
	after() throwing :  initialization(ErroneousExceptionConversion.new(..)) {
		System.out.println("After throwing");
	}
	
}