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.

ConstructorFlow.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.testing.Tester;
  3. /** @testcase from biojava: org/biojava/bio/dp/SimpleMarkovModel.java:384 */
  4. public class ConstructorFlow {
  5. final Runnable runner; // remove final and compile succeeds
  6. Runnable nonfinal;
  7. String one;
  8. /** @testcase PUREJAVA flow analysis where final variable set in another constructor */
  9. public ConstructorFlow(String one, String two) {
  10. this(one);
  11. runner.run(); // incorrect CE: Field runner might not have a value
  12. nonfinal.run(); // expecting NPE
  13. }
  14. public ConstructorFlow(String one) {
  15. this.one = one;
  16. runner = new Runnable() {
  17. public void run() {
  18. Tester.event("runner.run()");
  19. }};
  20. }
  21. public static void main(String[] args) {
  22. Tester.expectEvent("NullPointerException");
  23. Tester.expectEvent("runner.run()");
  24. try {
  25. new ConstructorFlow("one", "two");
  26. Tester.check(false, "expected NPE");
  27. } catch (NullPointerException npe) {
  28. Tester.event("NullPointerException");
  29. }
  30. Tester.checkAllEvents();
  31. }
  32. }