jContractor: Introducing Design-by-Contract to Java Using Reflective Bytecode Instrumentation | Formal Methods in System Design
Skip to main content

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

  • Published:
Formal Methods in System Design Aims and scope Submit manuscript

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.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Subscribe and save

Springer+ Basic
¥17,985 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Price includes VAT (Japan)

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. K. Arnout and R. Simon, “The .NET Contract Wizard: Adding Design by Contract to languages otherthan Eiffel,” in Proceedings of TOOLS 39, IEEE Computer Society, 2001.

  2. A.P. Black, “Exception Handling: The case against,” Technical Report TR-82-01–02, University of Washington Computer Sciences Department, January 1982.

  3. J. Cheesman and J. Daniels, UML Components–-A Simple Process for Specifying Component-Based Software, Addison-Wesley, 2000.

  4. Y. Cheon and G.T. Leavens, “A Runtime Assertion Checker for the Java Modelling Language(JML),” in International Conference on Software Engineering Research and Practice (SERP)2002, Las Vegas, Nevada, USA, June 24–27, 2002.

  5. I. Crnkovic and M. Larsson (ed.), Building Reliable Component-Based Software Systems, Artech House Publishers, July 2002.

  6. M. Dahm, Byte Code Engineering with the BCEL API, Technical Report B-17-98, Institut für Informatik, Freie Universität Berlin (1998).

  7. M.M. Detlef Bartetzko, Clemens Fischer, and H. Wehrheim, “Jass–-java with assertions,” Vol. 55, 2001.

  8. A. Duncan and U. Hölzle, “Adding Contracts to Java with Handshake,” Technical Report TRCS98-32, Department of Computer Science, University of California, Santa Barbara (1998).

  9. J.B. Goodenough, “Exception Handling: Issues and a proposed notation,” Communications of the ACM, Vol. 18, No. 12, 1975.

  10. C. Hoare, “An Axiomatic Basis for Computer Programming,” Communications of the ACM Vol. 12, No. 10, 1969.

  11. M. Karaorman, U. Hölzle, and J. Bruno, j Contractor: A Reflective Java Library to Support Design By Contract,” in Proceedings of Meta-Level Architectures and Reflection, 2nd International Conference, Reflection '99. Saint-Malo, France. Lecture Notes in Computer Science #1616, Springer Verlag, 1999, pp. 175–196.

  12. R. Kramer, Contract–-The Java Design by Contract Tool, in J.G. Madhu Singh, Bertrand Meyer and R. Mitchell, (eds.), Proceedings of TOOLS USA '98, Santa Barbara, California, August 3-7, 1998, 1998.

  13. T. Lindholm and F. Yellin, The Java Virtual Machine Specification, Addison-Wesley, Reading, 1999.

    Google Scholar 

  14. Man Machine Systems, “Design by Contract for Java Using JMSAssert,” Technicalreport, http://www.mmsindia.com/DBCForJava.html

  15. B. Meyer, Eiffel: The Language, Prentice Hall, New York, 1992.

    Google Scholar 

  16. R. Mitchell and J. McKim, Design by Contract, by Example, Addison-Wesley, Boston, 2001.

    Google Scholar 

  17. B. Meyer, “Object Oriented Software Construction,” 2nd ed. Prentice Hall, Upper Saddle River,1997.

    Google Scholar 

  18. G.T. Leavens, A.L. Baker, and C. Ruby, “JML: A notation for detailed design,” in H. Kilov, et al., (eds.), Behavioral Specifications of Businesses and Systems. Kluwer Academic Publishers, Boston, 1999, pp. 175–188.

    Google Scholar 

  19. D. Murray and D. Parson, “Automated Debugging in Java using OCL and JDI,” in Proceedings of Fourth International Workshop on Automated Debugging (AADEBUG 2000), Munich, August 2000.

  20. N. Nethercote and J. Seward, “Valgrind: A Program Supervision Framework,” in Proceedings of the Third Workshop on Runtime Verification (RV'03), Boulder, Colorado, USA, July 2003.

  21. Object Management Group, “OMG Unified Modeling Language Specification,” report version 1.3, June 1999, Object Management Group, 1999.

  22. R. Plosch, “Design by Contract for Python,” in Proceedings of Asic Pacific Software Engineering Conference, IEEE Computer Society, 1997.

  23. S. Porat and P. Fertig, “Class Assertions in C++,” Journal of Object Oriented Programming, Vol. 8, No. 2, pp. 30–37, 1995.

    Google Scholar 

  24. D. Thain and M. Livny, “Error Scope on a Computational Grid: Theory and Practice,” in Proceedings of the 11th IEEE Symposium on High Performance Distributed Computing (HPDC-11), Edinburgh, Scotland, July 2002.

  25. “Using Design by Contract to Automate Java Software and Component Testing,” Technical report,Parasoft Corporation. http://www.parasoft.com/jsp/products/Jcontract

  26. J. Warmer and A. Kleppe, The Object Constraint Language, Addison Wesley, 1999.

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Murat Karaorman.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Karaorman, M., Abercrombie, P. jContractor: Introducing Design-by-Contract to Java Using Reflective Bytecode Instrumentation. Form Method Syst Des 27, 275–312 (2005). https://doi.org/10.1007/s10703-005-3400-1

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10703-005-3400-1

Keywords