User Tools

Site Tools


invariant:ex4

Intro Ex1 Ex2 Ex3 Ex4 Ex5

Invariants: Sanitize input

Task: Pass tests.PointBounds.

Instead of throwing an exception when one of the int fields of Point is set to a negative value, write an aspect to trim the value to zero.

Tools: around advice; note that inside the body of an around advice, you can invoke a proceed statement with (possibly different) join point parameters.

Your aspect is going to look like this:

public aspect Answer4 {
  void around(int val): <pointcut> {
    <if necessary, sanitize val>
    proceed(val);
  }
}

With a correct implementation, you should pass tests.PointBounds.


When done, remove your aspect from the build path and continue with Exercise 5.

invariant/ex4.txt · Last modified: 2021/02/05 13:53 (external edit)