Automated Generation of Code Contracts: Generative AI to the Rescue?

Design by Contract represents an established, lightweight paradigm for engineering reliable and robust software systems by specifying verifiable expectations and obligations between software components. Due to its laborious nature, developers hardly adopt Design by Contract in practice. A plethora of research on (semi-)-automated inference to reduce the manual burden has not improved the adoption of so-called code contracts in practice. This paper examines the potential of Generative AI to automatically generate code contracts in terms of pre- and postconditions for any Java project without requiring any additional auxiliary artifact. To fine-tune two state-of-the-art Large Language Models, CodeT5 and CodeT5+, we derive a dataset of more than 14k Java methods comprising contracts in form of Java Modeling Language (JML) annotations, and train the models on the task of generating contracts. We examine the syntactic and semantic validity of the contracts generated for software projects not used in the fine-tuning and find that more than 95% of the generated contracts are syntactically correct and exhibit remarkably high completeness and semantic correctness. To this end, our fully automated method sets the stage for future research and eventual broader adoption of Design by Contract in software development practice.

Authors

Institutions

Publication Details

Published
2024-10-17
DOI
https://doi.org/10.1145/3689484.3690738
Citations
6
Primary Topic
Artificial Intelligence in Law
Type
article
Field-Weighted Citation Impact
13.39

Funders

Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Automated Generation of Code Contracts: Generative AI to the Rescue?

Manuel Ohrndorf, Noah Bühlmann, Oscar Nierstrasz, Sandra Greiner et al.
6 citations
Artificial Intelligence in Law
13.39
article

Automated Generation of Code Contracts: Generative AI to the Rescue?

Manuel Ohrndorf, Noah Bühlmann, Oscar Nierstrasz, Sandra Greiner, Christos Tsigkanos, Timo Kehrer
article en
6 citations

Abstract

Design by Contract represents an established, lightweight paradigm for engineering reliable and robust software systems by specifying verifiable expectations and obligations between software components. Due to its laborious nature, developers hardly adopt Design by Contract in practice. A plethora of research on (semi-)-automated inference to reduce the manual burden has not improved the adoption of so-called code contracts in practice. This paper examines the potential of Generative AI to automatically generate code contracts in terms of pre- and postconditions for any Java project without requiring any additional auxiliary artifact. To fine-tune two state-of-the-art Large Language Models, CodeT5 and CodeT5+, we derive a dataset of more than 14k Java methods comprising contracts in form of Java Modeling Language (JML) annotations, and train the models on the task of generating contracts. We examine the syntactic and semantic validity of the contracts generated for software projects not used in the fine-tuning and find that more than 95% of the generated contracts are syntactically correct and exhibit remarkably high completeness and semantic correctness. To this end, our fully automated method sets the stage for future research and eventual broader adoption of Design by Contract in software development practice.

University of Bern (CH), University of Southern Denmark (DK), National and Kapodistrian University of Athens (GR)
Hellenic Foundation for Research and Innovation
Openalex Percentile: Top 1%
Artificial Intelligence in Law
13.39
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Automated Generation of Code Contracts: Generative AI to the Rescue? — Manuel Ohrndorf, Noah Bühlmann, et al. · (2024) | TGRS Research Map | TGRS