JML and ESC/Java2: An Introduction Karl Meinke School of Computer Science and Communication, KTH.

Slides:



Advertisements
Similar presentations
Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
Advertisements

Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Extended Static Checking for Java Cormac Flanagan K. Rustan M. Leino Mark Lillibridge Greg Nelson James B. Saxe Raymie Stata Compaq SRC 18 June 2002 PLDI02,
Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 0 Summer school on Formal Models.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
An Abstract Interpretation Framework for Refactoring P. Cousot, NYU, ENS, CNRS, INRIA R. Cousot, ENS, CNRS, INRIA F. Logozzo, M. Barnett, Microsoft Research.
The Java Modeling Language JML Erik Poll Digital Security Radboud University Nijmegen.
Securing Java applets Erik Poll Security of Systems (SOS) group University of Nijmegen
Dept. of Computer Science A Runtime Assertion Checker for the Java Modeling Language (JML) Yoonsik Cheon and Gary T. Leavens SERP 2002, June 24-27, 2002.
Automated creation of verification models for C-programs Yury Yusupov Saint-Petersburg State Polytechnic University The Second Spring Young Researchers.
An Integration of Program Analysis and Automated Theorem Proving Bill J. Ellis & Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor Formal Methods in Software Engineering1.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Software Engineering and Design Principles Chapter 1.
An overview of JML tools and applications Lilian Burdy Gemplus Yoonsik Cheon, Gary Leavens Iowa Univ. David Cok Kodak Michael Ernst MIT Rustan Leino Microsoft.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Static and Dynamic Contract Verifiers For Java Hongming Liu.
Designing Classes How to write classes in a way that they are easily understandable, maintainable and reusable.
Houdini: An Annotation Assistant for ESC/Java Cormac Flanagan and K. Rustan M. Leino Compaq Systems Research Center.
Software Reliability Methods Sorin Lerner. Software reliability methods: issues What are the issues?
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Software Quality: Testing and Verification II. 2 1.A failure is an unacceptable behaviour exhibited by a system — The frequency of failures measures software.
JML TOOLS REVIEW & EVALUATION Chris Grosshans Mark Lewis-Prazen.
Lecture 4 Requirements Testing & Requirements Modeling.
Computer Science 340 Software Design & Testing Design By Contract.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Extended Static Checking for Java  ESC/Java finds common errors in Java programs: null dereferences, array index bounds errors, type cast errors, race.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Formal specification of Gemplus’ electronic purse case study Néstor Cataño & Marieke Huisman INRIA Sophia-Antipolis {ncatano,
Today’s Agenda  Quick Review  Continue on JML Formal Methods in Software Engineering1.
A Survey on Java Modeling Languages Gergely Kovásznai,Eszterházy Károly College Wolfgang Schreiner,Johannes Kepler University Gábor Kusper,Eszterházy Károly.
CIS 771: Software Specifications Lecture 18: Specifying and Checking Partial Properties of Java Code Copyright , Matt Dwyer, John Hatcliff, and.
© Andrew IrelandDependable Systems Group Static Analysis and Program Proof Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt University.
Spec# Andreas Vida. Motivation Correct and maintainable software Correct and maintainable software Cost effective software production Cost effective software.
 Asserting Expectations. Introduction -Observation alone is not enough for debugging as it can be a burden for a programmer. -One must compare observed.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata.
Verificare şi Validarea Sistemelor Soft Tem ă Laborator 1 ESC/Java2 Extended Static Checker for Java Dat ă primire laborator: Lab 1 Dat ă predare laborator:
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Early Detection of JML Specification Errors using ESC/Java2 Patrice Chalin Dependable Software Research Group (DSRG) Computer Science and Software Engineering.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
L13: Design by Contract Definition Reliability Correctness Pre- and post-condition Asserts and Exceptions Weak & Strong Conditions Class invariants Conditions.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Institute for Applied Information Processing and Communications (IAIK) – Secure & Correct Systems 1 Static Checking  note for.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
Combining Static and Dynamic Reasoning for Bug Detection Yannis Smaragdakis and Christoph Csallner Elnatan Reisner – April 17, 2008.
ESCJ 14: ESC/Java Project Review Slides March 6th, 1997.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Formal Techniques (CS340 © John C. Knight 2004)
Accessible Formal Methods A Study of the Java Modeling Language
CSE 143 Error Handling [Section 2.8] 3/30/98 CSE 143.
Programming Languages 2nd edition Tucker and Noonan
Hoare-style program verification
Java Modeling Language (JML)
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Computer Science 340 Software Design & Testing
Programming Languages 2nd edition Tucker and Noonan
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

JML and ESC/Java2: An Introduction Karl Meinke School of Computer Science and Communication, KTH

Java Modeling Language (JML) A behavioural interface specification language for Java Design-by-contract paradigm (Eiffel) Lightweight, usable by practising programmers Add assertions to Java source code, e.g. Method preconditions Method postconditions Class invariants Assertions are extended Java boolean expressions, added through comments in.java files: / “my JML stuff” ∗ / ”my JML stuff”

Method Pre- and Postconditions Wallet Example: requires amount >= 0; ensures balance == \old(balance) − amount; ensures \result == balance; public int debit(int amount) {... } \old(E ): refers to E in the state before the method call \result: refers to the return value

Class Invariants Wallet Example: public class Wallet { public static final short MAX_WALLET; private short balance; / invariant 0 <= balance && balance <= MAX_WALLET; ∗ /... } Class invariants must be: Preserved by all methods in a class, i.e. implicitly included in both the pre- and postconditions of methods; Established by all constructors, i.e. implicitly included in postconditions of constructors

Other Annotations Assumptions used but not checked (cf. math axioms): e.g. assume x+y==y+x; Exceptional postconditions: requires amount >= 0; ensures balance == \old(balance) + amount; exsures (WalletOverflow) balance == \old(balance) ; public int credit(int amount) throws WalletOverflow {... } Only WalletOverflow can be thrown, and whenever it is thrown balance == \old(balance) holds (no action!). Assertions both used and checked: e.g. assert balance = 0;

ESC/Java2 Extended Static Checker originally developed at Compaq Systems Research Center, now an open-source project maintained by Kiniry et al. at University College Dublin. Features and properties: Checks JML-annotated java code automatically or interactively Unsound: does not find all incorrect annotations Incomplete: may report nonexistent errors Good at routine checks of relatively simple properties – null dereferences – Array indices out-of-bounds Unsuitable for complete program verification – Theorem prover built to be automatic – Loops only traversed once

ESC/Java2 Benefits Highlights of static checking: Automatic use, only annotation overhead Finds more advanced properties than type checkers Forces important properties to be explicitly recorded Makes it easier to understand and maintain code Success stories from experimental use in real-world Design-by-contract paradigm especially useful when program reliability and security is paramount!

Loop Invariant Example Consider the following method: public static int plus(int x, int y) { int s = 0; int i = x; while (i != 0) { s = s + y; i = i − 1; } return s; } A loop invariant is a property that is true before the loop before and after the loop body Loop invariants can be checked by ESC/Java2 if the loop_invariant pragma is used.

Loop Invariant Example, Continued The annotated code: axiom (\forall int i, j, k; i ∗ (j − k) == i ∗ j − i ∗ k); requires x >= 0; ensures \result == y ∗ x; public static int plus(int x, int y) { int s = 0; int i = x; loop_invariant s == y ∗ x − y ∗ i; while (i != 0) { s = s + y; i = i − 1; } return s; } Loop invariant captures what really goes on in the loop!

Further reading Information about JML and related tools: ESCJava2 documentation and downloads: Pointers to information about formal methods: More examples and links:

Alternatives to JML/ESCJava2 (1) Alloy: was developed in the hope of adapting first-order logic to allow fully automatic analysis. To do this Alloy sacrifices the ability to totally prove a system's correctness. Rather, it attempts to find counterexamples within a limited scope that violate the constraints of the system. Alloy was developed by the Software Design Group at MIT. In 1997 they produced the first Alloy prototype, which was then a rather limited object modelling language. Over the years Alloy has developed into a full structural modelling language capable of expressing complex structural constraints and behaviour.

Alternatives to JML/ESCJava2 (2) Object Constraint Language (OCL) is the constraint language of UML. It was developed at IBM and ObjecTime Limited and was added to the UML in Because it was initially designed to be an annotation language for UML class diagrams, it does not include a textual notation for declarations. Variants of OCL such as USE overcome this limitation. Many tools are available supporting OCL such as Octopus and the Eclipse Model Development Tools. Typical features include the interpretation of OCL constraints over test cases and code generation. Some, such as the USE tool mentioned above, support design-time analysis and allow exhaustive search over a finite space of cases similar to Alloy.

Alternatives to JML/ESCJava2 (3) Vienna Development Method (VDM) is a set of techniques for developing computer systems. It originated from IBM's Vienna Laboratory in the mid-1970s In 1988 Peter Froome developed a tool called SpecBox which was the first industrialised tool for checking VDM specification. SpecBox is used in civil nuclear, railway and security applications. There are many other tools for checking VDM specification such as IFAD VDM-SL and Centaur-VDM environment which is an interactive and graphical tool for VDM. However unlike Alloy these do not provide fully automatic analysis in the style of a model checker. Both Alloy and VDM support object-orientation and concurrency. VDM has been standardized and is still widely used in industry by such organisations as British Aerospace Systems & Equipment, Rolls Royce and Dutch Department of Defence. Alloy is not used as much in industry as VDM.