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.

Bug.java 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import java.lang.annotation.Inherited;
  2. import java.lang.annotation.Retention;
  3. import java.lang.annotation.RetentionPolicy;
  4. public class Bug {
  5. public static void main(String[] args) {
  6. MonitorMyAnnotationExecution.aspectOf().executionCount = 0;
  7. new ClassImplementingInterfaceWithInheritedAnnotation();
  8. if (MonitorMyAnnotationExecution.aspectOf().executionCount!=1) {
  9. throw new RuntimeException();
  10. }
  11. MonitorMyAnnotationExecution.aspectOf().executionCount = 0;
  12. new ClassExtendingClassWithInheritedAnnotation();
  13. // Expecting 2, one for derived and one for base class ctor execution
  14. if (MonitorMyAnnotationExecution.aspectOf().executionCount!=2) {
  15. throw new RuntimeException();
  16. }
  17. }
  18. }
  19. @Retention(RetentionPolicy.RUNTIME)
  20. @Inherited
  21. @interface InheritedAnnotation { }
  22. @InheritedAnnotation
  23. interface InterfaceWithInheritedAnnotation { }
  24. @InheritedAnnotation class ClassWithInheritedAnnotation { }
  25. class ClassImplementingInterfaceWithInheritedAnnotation implements InterfaceWithInheritedAnnotation { }
  26. class ClassExtendingClassWithInheritedAnnotation extends ClassWithInheritedAnnotation { }
  27. aspect MonitorMyAnnotationExecution {
  28. int executionCount;
  29. before() : execution((@InheritedAnnotation *)+.new(..)) && !within(Monitor*) && !within(Bug) {
  30. executionCount++;
  31. }
  32. }