jContractor: A Reflective Java Library to Support Design By Contract
Murat Karaorman, Urs Hölzle, John Bruno
Abstract: jContractor is a purely library and design-pattern
based approach to support Design By Contract specifications such as preconditions,
postconditions, class invariants, and recovery and exception handling in
Java. jContractor uses an intuitive naming convention, and standard Java
syntax to instrument Java classes and enforce Design By Contract constructs.
The designer of a class specifies a contract by defining protected methods
which conform to the jContractor design patterns. jContractor uses Java
Reflection to synthesize an instrumented version of a Java class containing
jContractor contract specifications. The instrumented version contains
code which enforces the Design By Contract specifications. Programmers
enable the run-time enforcement of contracts by either incorporating the
jContractor class loader or by instantiating objects directly from
the instrumented subclass through the jContractor factory. Programmers
can use exactly the same syntax for invoking methods and passing object
references regardless of whether contracts are present or not. Since jContractor
is purely library-based, it works with any Java implementation and requires
no special tools such as modified compilers, modified JVMs, or pre-processors.
Technical Report TRCS98-31, Computer Science Department, University
of California, Santa Barbara, December 1998
To get the PostScript file, click here
(PDF is here).