Adding Contracts to Java with Handshake
Andrew Duncan, Urs Hölzle
Abstract: Contracts describe an agreement between the writer and the user
of a class. Their use enhances programmer productivity and program reliability,
especially in library code. Handshake provides contracts for Java classes and
interfaces in the form of class invariants and method pre- and postconditions.
Using Handshake, a programmer can add contracts to classes and interfaces
without needing access to their source code, without changing the class files,
and without changing the JVM implementation. Unlike existing implementations of
contracts for Java, Handshake intercepts the VM's file operations and modifies
classes on the fly without requiring any modification to the JVM itself. By
using a dynamic link library interposed between the VM and the operating system,
the system is relatively simple to port to a new OS and works with a variety of
JVM implementations. The system imposes very little overhead other than the time
required to evaluate the contract's boolean expressions themselves.
Technical Report TRCS98-32, Computer Science Department, University of
California, Santa
Barbara, December 1998
To get the PostScript file, click here
(PDF is here).