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.

OddConstructors.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import java.lang.reflect.*;
  2. import org.aspectj.testing.Tester;
  3. public class OddConstructors {
  4. public static void main(String[] args) throws Exception { test(); }
  5. public static void test() throws Exception {
  6. new OddConstructors().go();
  7. Tester.check("advised default constructor");
  8. Tester.checkEqual(B.aspectOf().count, 1, "new'd once");
  9. }
  10. void go() throws Exception {
  11. // new C();
  12. // use reflection instead of new to create this class to tickle the bug
  13. Constructor c = Class.forName("C").getConstructor(new Class[0]);
  14. I i = (I)c.newInstance(new Object[0]);
  15. }
  16. static aspect B extends A issingleton() { //of eachJVM() {
  17. pointcut i(): target(I);
  18. }
  19. }
  20. abstract aspect A {
  21. abstract pointcut i();
  22. pointcut j():
  23. i()
  24. // 2001.08.01 (palm)
  25. // Had to change this to I.new from new
  26. // because of the change to the meaning
  27. // of initialization
  28. //&& initialization(new(..)) ;
  29. && initialization(I.new(..)) ;
  30. after() returning: j() {
  31. Tester.note("advised default constructor");
  32. count++;
  33. }
  34. int count = 0;
  35. }
  36. class C implements I { public C() {} }
  37. interface I {}