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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import org.aspectj.testing.Tester;
  2. aspect Test {
  3. public static boolean invariant() { return true ; }
  4. after() returning : call(static void AssertInAdviceBug.call() ) {
  5. assert !invariant() ;
  6. }
  7. void around(): call(static void call1()) {
  8. assert !invariant();
  9. }
  10. static void AssertInAdviceBug.call2() {
  11. assert !invariant();
  12. }
  13. }
  14. /** @testcase PR#657 PUREJAVA assert statement in advice [requires 1.4] */
  15. public class AssertInAdviceBug {
  16. private static boolean useJavacMode = false;
  17. public static void main(String[] args) {
  18. AssertInAdviceBug.class.getClassLoader().setClassAssertionStatus("Test", true);
  19. AssertInAdviceBug.class.getClassLoader().setClassAssertionStatus("AssertInAdviceBug", false);
  20. boolean gotAssert = false;
  21. try {
  22. call();
  23. } catch (AssertionError e) {
  24. gotAssert = true;
  25. StackTraceElement[] stack = e.getStackTrace();
  26. // this test should only run when we're not in -usejavac mode
  27. if (stack[0].getFileName().endsWith("AssertInAdviceBug.java")) {
  28. Tester.checkEqual(stack[0].getLineNumber(), 6, "bad line for assert");
  29. } else {
  30. useJavacMode = true;
  31. System.err.println("!!!!!!!!!!!!!!!!!!!!!!!IN JAVAC MODE!!!!!!!!!!!!!!!!!!!!1");
  32. }
  33. }
  34. Tester.check(gotAssert, "no assert");
  35. gotAssert = false;
  36. try {
  37. call1();
  38. } catch (AssertionError e) {
  39. gotAssert = true;
  40. StackTraceElement[] stack = e.getStackTrace();
  41. // this test should only run when we're not in -usejavac mode
  42. if (!useJavacMode) {
  43. Tester.checkEqual(stack[0].getLineNumber(), 10, "bad line for assert");
  44. }
  45. }
  46. Tester.check(gotAssert, "no assert on call1");
  47. gotAssert = false;
  48. try {
  49. call2();
  50. } catch (AssertionError e) {
  51. gotAssert = true;
  52. StackTraceElement[] stack = e.getStackTrace();
  53. //e.printStackTrace();
  54. // this test should only run when we're not in -usejavac mode
  55. if (!useJavacMode) {
  56. Tester.checkEqual(stack[0].getLineNumber(), 14, "bad line for assert");
  57. }
  58. }
  59. Tester.check(gotAssert, "no assert on call1");
  60. }
  61. public static void call() {}
  62. public static void call1() {}
  63. }