What is ezContract?
ezContract is a Java implementation of Design By
Contract (DBC) for the Java language. Through the use of markers which are
predefined dummy methods and attributes, ezContract proposes a new way to
annotate contracts. The annotated programs can be directly compiled by standard
Java compilers. A bytecode instrumentor is developed to manipulate the bytecode
to inject contract evaluation instructions and make the contracts executable at
runtime. The marker approach avoids two primary problems found in the existing
practices: source compatibility that depends on language extension and symbolic
barrier that leaves contracts and their targets unrelated. It also facilitates
streamlined integration with IDEs and improves
readability as well as writability of the contract-annotated programs.
Motivation and background
DBC has been generally acknowledged as a useful
and pragmatic technique to build reliable software systems. However, its use
has so far been restricted due to the lack of support by the mainstream
programming languages such as Java and C++. Currently, the Eiffel language is
the only commercial language that fully supports DBC. The situation has not
escaped the attentions from the research community; numerous researches on
porting DBC into other languages have been conducted. However, the results so
far fall short in making DBC a standard practice by software developers on real-world
projects. The main reasons include the following:
1.
DBC
is a paradigm shift in programming and the design of programming languages. The
existing researches mainly focus on implanting DBC from Eiffel into new
languages. The language compatibility issues have been largely overlooked,
which make the use of DBC awkward or even incorrect.
2.
The
concept of DBC includes both software correctness and robustness. Most of the
existing researches merely focus on software correctness and rarely touch the
robustness issue. In the DBC context robustness is related to throwing,
catching, and handling exception caused by contract violation.
3.
A
DBC-enabled programming language alone will not be sufficient to support
DBC-based software development in the real world. Tool support in the
integrated development environments (IDE) is a critical issue for a DBC-enabled
programming language to be widely adopted. In the existing researches to
porting DBC to other languages, tool support issues have been largely ignored.
Founded by the National Science Council of Taiwan,
we execute a research project to investigate and resolve the above issues. In
particular, our research focuses on the support of DBC in the Java programming
language, which is platform independent and widely used. To achieve this, we
propose solutions that make using a new object-oriented library, a bytecode
instrumentor, a Java exception handling architecture, and supporting tools.
Scope of ezContract
DBC intends to build reliable software by
improving the two quality attributes: correctness and robustness. In DBC,
correctness is addressed by contracts and robustness is tackled by exception
handling. Each of the issues is complicated on its own. To adopt DBC in Java,
we established two projects, ezContract and ezException,
to tackle contracts and exception handling issues, respectively. People who are
interested in exception handling are encouraged to visit the exException project:
https://sourceforge.net/projects/ezexception/.
Current status of ezContract
ezContract has been developed since March 2005.
Currently, ezContract supports the following features of DBC:
1.
Specifying
preconditions, postconditions, and class invariants for Java classes and
interfaces, with and without source code.
2.
Evaluating
contracts defined in classes.
3.
The
ability to use old expressions (the value before entering a method) and to
access the result (i.e., the return value of a method) in postconditions.
4.
Subcontracting
support. That is, preconditions are or-ed, and
postconditions and class invariants are and-ed with
those of the parent class, respectively.
5.
The
ability to show correct line number in source code when contracts is violated
(facilitating debugging).
Development plan
1.
Evaluating
contracts defined in interfaces. Current version of ezContract can only
evaluate contracts defined in classes. Although specifying contracts in
interfaces is supported, the bytecode instrumentor is yet to produce contract
evaluation code for interfaces.
2.
Instrumenting programs at bytecode loading time. Currently, the
instrumented programs must be written to disk and can be loaded with a default
Java class loader. A specific class loader will be developed to support
instrumentation on the fly (i.e., at class loading time).
3.
Integrated
with Eclipse. Developing an Eclipse plug-in to check the usage of ezContract.
For example, using old expresses and accessing the result in precondition
should not be allowed. The plug-in will check any violation of the usage of
ezContract at compile time and generate warnings and suggestions for
developers.
The history of ezContract
ezContractor was introduced the paper titled " ezContract:
Using Marker Library and Bytecode Instrumentation to Support Design by Contract
in Java ", by Yu Chin Cheng, Chien-Tsun Chen, and Chin-Yun Hsieh at the year 2007. However, ezContractor has been design and developed since
2005. In the end of 2007, we decided to release ezContract (and ezException) as open source software.
Licensing
ezContract is released under the Eclipse Public License.
ezContract at SourceForge
ezContract is hosted in https://sourceforge.net/projects/ezcontract/.