You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AfterThrowingCtor.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // pr44586
  2. import org.aspectj.testing.Tester;
  3. public aspect AfterThrowingCtor {
  4. after() throwing (Throwable t) : execution(Foo*.new(..)) {
  5. throw new AdviceRanException();
  6. }
  7. public static void main(String args[]) {
  8. try {
  9. new Foo();
  10. Tester.checkFailed("Advice should not run here");
  11. } catch(IllegalStateException illEx) {
  12. // good, we do not want the advice to run as the
  13. // initialization of an itd field is considered part
  14. // of the initialization join point, but not the execution
  15. // join point.
  16. }
  17. try {
  18. new Foo1();
  19. Tester.checkFailed("Advice should run here");
  20. } catch(AdviceRanException arEx) {
  21. // good, the advice should run as the field initialisation is considered
  22. // part of the execution join point.
  23. }
  24. }
  25. private Object Foo.val = Foo.initVal();
  26. class AdviceRanException extends RuntimeException {};
  27. }
  28. class Foo {
  29. Foo() {
  30. }
  31. static Object initVal() {
  32. throw new IllegalStateException("crash");
  33. }
  34. }
  35. class Foo1 {
  36. Foo1() {
  37. }
  38. private Object val = initVal();
  39. static Object initVal() {
  40. throw new IllegalStateException("crash");
  41. }
  42. }