User Tools

Site Tools


invariant:ex1

Intro Ex1 Ex2 Ex3 Ex4 Ex5

Invariants: Find old tracing

Task: Signal an error for output on the standard output channel System.out.

We typically use the idiom System.out.println() for one-off debugging traces. It's a common mistake to leave these in your system far longer than is necessary. Create an aspect with the implementation given below to signal an error at compile time if this mistake is made.

package answers;
 
aspect Answer1 {
  declare error:
    get(java.io.PrintStream System.out) && within(figures..*):
      "Illegal access to System.out";
}
Note that this answer does not say that the call to the println() method is incorrect, rather, that the field get of the out field is illegal. Indeed, it is not a mistake in general to use the println() method.

When you use this on the given system, you'll find one incorrect trace in SlothfulPoint.


Comment out the offending output line and continue with Exercise 2.

invariant/ex1.txt · Last modified: 2021/02/05 13:53 by 127.0.0.1