jContractor: Introducing Design-by-Contract to Java Using Reflective Bytecode Instrumentation

  • Authors:
  • Murat Karaorman;Parker Abercrombie

  • Affiliations:
  • Texas Instruments, Inc., Santa Barbara, USA 93117;College of Creative Studies, University of California, Santa Barbara, USA 93106

  • Venue:
  • Formal Methods in System Design
  • Year:
  • 2005

Quantified Score

Hi-index 0.00

Visualization

Abstract

Design by Contract is a software engineering practice that allows semantic information to be added to a class or interface to precisely specify the conditions that are required for its correct operation. The basic constructs of Design by Contract are method preconditions and postconditions, and class invariants.This paper presents a detailed design and implementation overview of jContractor, a freely available tool that allows programmers to write "contracts'' as standard Java methods following an intuitive naming convention. Preconditions, postconditions, and invariants can be associated with, or inherited by, any class or interface. jContractor performs on-the-fly bytecode instrumentation to detect violation of the contract specification during a program's execution. jContractor's bytecode engineering technique allows it to specify and check contracts even when source code is not available. jContractor is a pure Java library providing a rich set of syntactic constructs for expressing contracts without extending the Java language or runtime environment. These constructs include support for predicate logic expressions, and referencing entry values of attributes and return values of methods. Fine grain control over the level of monitoring is possible at runtime. Since contract methods are allowed to use unconstrained Java expressions, in addition to runtime verification they can perform additional runtime monitoring, logging, and analysis.