ESC/Java2 assignment

ESC/Java2 assignment

     [http://www.cs.ru.nl/~erikpoll/Teaching/SenL2/index.html]

Purpose of this exercise is to see what all these semantics and logics are good for: once we formalise semantics of real programming languages and develop associated logics we can build tools to improve the quality of software.

The slides presented at the lecture are available here

The program verification tool ESC/Java2

ESC/Java2 is an automated program verification tool (aka extended static checker) for Java programs. It implements a Hoare logic for reasoning over Java programs that have been annotated with JML specifications. These specifications express for instance preconditions, postconditions, and invariants, and can be added as assertions to the program code. Essentially, ESC/Java2 computes weakest preconditions of methods, and then sends the resulting proof obligiations to the automated theorem prover Simplify. The user never get to see these proof obligiations or the back-end theorem prover; instead, the tool gives feedback over which assertions it could not prove.

Running ESC/Java2

ESC/Java2 is available on the central UNIX machines (e.g. solost) and on the Windows PCs in the terminal rooms. You can also download it on your own machine. Instructions for this:

The assignment

For the assignment, you should specify the two classes
  1. Bag.java
  2. Amount.java
with JML and run ESC/Java2 to verify these specifications. Simply put, you have to run ESC/Java2 on these files, and, if the tool produces some warning, to make the warning go away. You have to use your own best judgement to choose between these two options, but there are some deliberate bugs in the code for you to detect, with the help of the tool.

For Amount.java you must also try to formalise the informal invariant that is discussed in the file in JML, which should reveal some problems in the code.

In the end, ESC/Java2 should run without any complaints on the annotated code. ESC/Java2 complains (among other things) if it thinks a runtime exception may occur, say a NullPointerException, so if ESC/Java2 runs without complaints this means it has verified that no runtime exceptions can occur.

More detailed instructions are given in the Java files. Read these!

The only JML keywords you'll need to use for this are requires, invariant, and ensures. If you want, you can also use non_null as an abbreviation and experiment with other features.

Inleveren via email naar Erik Poll (erikpoll@cs.ru. etc) of laat het gewoon even zien dat je een opgave afhebt tijdens het practicum op maandag. Gelieve de oplossingen - de geannoteerde Java files - gewoon direct als attachment aan je email te plakken, en niet te zippen, tarren oid, of nog ergeer, door diffs op te sturen. Dat scheelt veel gedoe met de afhandeling.

Some hints to keep you out of trouble with the tool:

Reflection

Some questions to consider
  1. In the end, do you think that you found all problems? Are you certain now that the code is correct?
  2. Can you think of ways in which the tool or the specification language could be improved?
  3. Instead of the tool we used, can you think of other ways (formal or informal, tool-supported or not) to find the problems that the tool found? If so, would these alternatives
    • find fewer of the problems, the same, or more?
    • find problems sooner or later than the current approach?
    • require more work or less work?
    • provide you with more confidence or less confidence that the code is correct?