Bringing Design by Contract to Modern Java: Revisiting C4J for Current Java Versions

Initial Situation: Design by Contract (DbC) is a software engineering methodology that aims to improve software quality by formally specifying contracts between software components through preconditions, postconditions, and invariants. One implementation of this methodology for Java is C4J (Contracts for Java) by Jonas Bergström. C4J enables developers to integrate DbC principles into Java applications in a practical way. However, the framework currently only supports Java 8 and relies on instrumentation mechanisms such as Java Agents and Javassist-based bytecode manipulation approaches that are deprecated or no longer fully compatible with modern Java versions. As Java has evolved significantly in terms of modularization, runtime restrictions, and instrumentation APIs, the applicability of C4J to current Java versions is limited. C4J was originally developed as a Design by Contract framework for Java and aims at integrating contract checking seamlessly into software development.

Goal: The goal of this thesis is to investigate how the methodology and concepts of C4J can be transferred to and integrated into current Java versions. The student should analyze the existing implementation and identify the technical limitations caused by deprecated instrumentation mechanisms. Based on this analysis, alternative approaches should be explored and prototypically evaluated to enable contract checking in modern Java environments. Potential directions include modern bytecode manipulation frameworks, annotation processing, compiler plugins, aspect-oriented approaches, or other mechanisms compatible with recent Java releases. The final outcome should include a proof-of-concept implementation and an evaluation of feasibility, limitations, and potential performance implications. A very rough proof of concept that may serve as a starting point for exploration (its applicability and quality still need to be evaluated) can be found at dbcagent repository.

Required Skills: Fundamental, object-oriented programming skills are necessary, and a willingness to learn.

Helpful Skills:

  • Knowledge in (or willingness to learn) Java and the Java ecosystem
  • Interest in software engineering methodologies and software quality assurance
  • Knowledge in (or willingness to learn) bytecode instrumentation or compiler/runtime technologies
  • Experience with software analysis and prototypical implementation