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.

DeclareWarning.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /** @testcase PR#31724 omnibus declare-warning test */
  2. public class DeclareWarning {
  3. static {
  4. if (null == System.getProperty("ignore")) { // CW 5
  5. throw new Error("never thrown");
  6. }
  7. }
  8. static int staticInt;
  9. int instanceInt;
  10. public static void main (String[] args) {
  11. DeclareWarning dw = new DeclareWarning(); // CW 12..18
  12. int i = staticInt;
  13. i = dw.instanceInt;
  14. staticInt = 2;
  15. dw.instanceInt = 2;
  16. run();
  17. dw.irun();
  18. throw new Error("compile-only test");
  19. }
  20. public static void run() {} // CW 21..23
  21. public void irun() {}
  22. public DeclareWarning() {
  23. try {
  24. long l = System.currentTimeMillis();
  25. if (0l == l) {
  26. throw new Error("never thrown");
  27. } else if (1l == l) {
  28. throw new RuntimeException("never thrown");
  29. } else if (2l == l) {
  30. throw new OutOfMemoryError("never thrown");
  31. }
  32. } catch (OutOfMemoryError e) {
  33. // CW 34
  34. System.err.println("never run");
  35. } catch (Error e) {
  36. // CW 37
  37. System.err.println("never run");
  38. } catch (RuntimeException x) {
  39. // CW 40
  40. System.err.println("never run");
  41. }
  42. }
  43. }
  44. aspect A {
  45. declare warning: staticinitialization(DeclareWarning)
  46. : "staticinitialization(DeclareWarning)";
  47. declare warning: initialization(DeclareWarning.new(..))
  48. : "initialization(DeclareWarning)";
  49. declare warning: get(int staticInt) : "get staticInt";
  50. declare warning: get(int instanceInt) : "get instanceInt";
  51. declare warning: set(int staticInt) : "set staticInt";
  52. declare warning: set(int instanceInt) : "set instanceInt";
  53. declare warning: call(void run()) : "call(void run())";
  54. declare warning: call(void irun()) : "call(void irun())";
  55. declare warning: call(DeclareWarning.new())
  56. : "call(DeclareWarning.new())";
  57. declare warning: execution(void run()) : "execution(void run())";
  58. declare warning: execution(void irun()) : "execution(void irun())";
  59. declare warning: execution(DeclareWarning.new())
  60. : "execution(DeclareWarning.new())";
  61. declare warning: handler(Error) : "handler(Error)";
  62. declare warning: handler(OutOfMemoryError) && within(DeclareWarning)
  63. : "handler(OutOfMemoryError) && within(DeclareWarning)";
  64. declare warning: handler(RuntimeException)
  65. && withincode(DeclareWarning.new())
  66. : "handler(RuntimeException) && withincode(DeclareWarning.new())";
  67. declare warning: adviceexecution() && within(A)
  68. : "adviceExecution() && within(A)";
  69. before() : initialization(DeclareWarning.new(..)) { // CW 72
  70. long l = System.currentTimeMillis();
  71. if (0l == l) {
  72. throw new Error("never thrown");
  73. }
  74. }
  75. }