User Tools

Site Tools


invariant:ex4

This is an old revision of the document!


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.1172480247.txt.gz · Last modified: 2007/02/26 09:57 by bdefrain