Contents:
As always, please read the entire handout before you start work.
Programmers hate to do by hand anything that can be automated. This includes formal verification: it is an important and useful way to ensure that your program is correct, but it can be tedious to do by hand, and especially if it has to be redone every time that your program changes.
In this assignment, you will get experience with automated program verification, in which you write a specification and the ESC/Java2 system performs a proof of correctness for you. This experience should help to solidify your understanding of the basics of reasoning about programs. It will also help you to understand a new technology that, though not widespread today, is increasingly being used in software development where correctness is important.
Your job in this problem set is to verify the correctness of 3 small programs using ESC/Java2, the Extended Static Checker for Java. You will use both the Eclipse and the VeriWeb interfaces demoed in class, using one interface for the first two problems and the other for the third. The order that you will complete the assignment in has been determined randomly — you will receive an email containing this order.
Each program consists of two classes — an abstract data type (ADT) and a client class that calls it. You will create and/or edit annotations in the source code of the ADT. You will not write write annotations in the client code. Your goal is to enable ESC/Java to verify that neither the ADT nor the calling code may ever terminate with a runtime exception. That is, when ESC/Java produces no warnings or errors on both the ADT and the calling code, your task is complete.
For each program, please allocate 1 hour of uninterrupted time to complete the verification task. (Some tasks may take less time; for others, you may not be finished when the hour runs out). Feel free to take breaks in between tasks, but please do not read email, etc. while you are working on a program. In total, you will spend around 5 hours on this assignment.
You are not permitted to collaborate with other students on this problem set. This problem set will help us understand the usability of program verification tools for CSE331 students; we are interested in your ability to use the interfaces, not your ability to collaborate!
ESC/Java is a tool that statically checks certain program properties. Users express the properties via source comments, similar to assertions or Java annotations. ESC reads the source code (and annotations) and warns about annotations that might not be universally true. ESC also warns about potential runtime exceptions such as null dereferences and array bounds errors.
ESC annotations are written in the Java Modeling Language (JML). In general, ESC supports annotations anywhere in the source code. However, in this problem set, you will only use annotations that specify properties of an abstract data type. Specifically, you will write a representation invariant (also known as an object invariant) and method specifications (preconditions and postconditions).
ESC is a modular checker: it reasons about code by examining one method at a time. Therefore, ESC both checks and depends on annotations. For instance, if an annotation describing the return value of an observer method is missing, ESC may not be able to prove a result about a method that calls that observer. This is exactly the same as other modular verification tools, such as type-checkers including the Nullness Checker. It is also the way a human performs an inductive proof of correctness for a data structure.
No setup is required. You will use Eclipse and its ESC/Java2 plugin via remote desktop. You will use VeriWeb from a web browser. As usual, you will submit the assessments by committing the files to your SVN repository.
By now you should have received an email at your @cs
account containing:
If you have not received an email with this information, please contact the course staff immediately.
We do not expect that everybody will complete all the tasks within the given time bounds — the tasks are (intentionally) of varying difficulties. As such, your grade on this assignment will not be determined by whether or not you complete the verification tasks. Rather, we will determine your grade by (1) whether or not you attempted the tasks and (2) your written response for the assessments.
Remote Desktop into the server specified in the staff email:
On Windows
On Linux
@cs
username and the
password provided in the email; Eclipse will automatically
load. Closing Eclipse will close your session, so don't do that until you are done with the project.Click the "Open Perspective" button to the left of the Java perspective button above the class outline view. Click "Other..." in the drop-down menu.
In the dialog that opens, select "Verification" and click "OK".
We have setup the ESC/Java2 plugin for you. However, before beginning the assignment, please confirm the following configuration (performing the steps as needed):
Windows → Preferences → Prover Editor → Simplify
Windows → Preferences → Java → ESC/Java2
After setting these options, you may need to close Eclipse (log out) and log back in for them to take effect.
To run ESC/Java2 on a project, package, or file:
Select the project, package, or file in the Package Explorer. For example:
Click the green check-mark in the toolbar to run ESC/Java2 on the selected project, package, or file; clicking the red X will remove ESC/Java2 warnings from the selected object.
Note: if you run ESC/Java2 on a single file, only that file is passed to the checker — types and methods from other files will not be found. For example, running the checker on StackArCheck.java will result in an error that ESC/Java2 cannot find type StackAr.
ESC/Java's output is shown in the console; additionally, errors are marked and underlined in the source files (just like compilation errors and warning). You can view the warning message at a location by hovering your mouse over the squiggly red line or over the corresponding red and white "E" on the left side of the editor.
NOTE: There is a known bug in the ESC/Java2 Eclipse plugin that causes the following error / caution to be generated for each file when run on Windows:
Caution: Using given file as the .java file, even though it is not the file for XXX on the classpath
You can (and should) safely ignore this error.
VeriWeb works best in Chrome and Firefox. Do not use another browser (e.g., Internet Explorer) because the interface may not function properly.
@cs
username and select the project to
verify. Click "OK"You can move the split bars to change the size of the three main information regions. For example, to give yourself more space to see long invariants in the drag and drop interface, move the vertical slider to the right.
Just about the only case where ESC/Java and VeriWeb can provide human-readable feedback about why a clause failed to verify is when the clause in syntactically incorrect or has a type error.
The only way to leave a precondition problem is to either eliminate all of the ESC/Java2 warnings for the method or to signal that the specs for a method that it calls are deficient.
If the user interface becomes unresponsive, reload the page.
This section contains the instructions for the Eclipse user interface. If the email you received states that you should use the VeriWeb interface first, follow the instructions for VeriWeb first and return to this section later.
Before using the Eclipse interface on the main projects, familiarize yourself with the interface by verifying the warm-up project FixedSizeSet, an ADT representing a mutable set of integers drawn from the range [0..7].
Follow the instructions in the next section for the FixedSizeSet project, taking as much time as you need. If you get stuck, you can "cheat" by referring to the included project FixedSizeSet-Solved, which contains a set of annotations that permit ESC to verify the ADT and the client. This is only one possible solution among many; your solution might include more / different annotations. The purpose of looking at the solution is to help your skills in reasoning about programs, not just to get you through the warm-up quickly. Most students won't need to look at the solutions, but if you do, make it a learning experience.
Don't hesitate to ask the course staff questions about the tool / verification during the warm-up.
When finished, compare your solution to the one provided in FixedSizeSet-Solved.
Follow these instructions for each project that you are instructed to verify with the Eclipse interface.
Spend at most 1 hour adding/removing/editing method preconditions, method postconditions, and representation invariants so that ESC/Java2 reports no errors or warnings. Re-run ESC/Java as many (or as few) times as you'd like. Do not modify any Java statements or expressions in the source code. Also, do not add/edit the annotations in the client file.
For the main projects — i.e., not the warmup — we have included invariants in the ADT file that were inferred with the Daikon tool. Feel free to remove/edit these invariants or to retain (some of) them, whatever you find most useful.
@nowarn
, @assume
,
or @axiom
).
Please answer the following questions in a file named eclipse.txt in your answers/ directory. There are no wrong or right answers, but we expect your answers to be thoughtful.
This section contains the instructions for the VeriWeb user interface. If the email you received states that you should use the Eclipse interface first, follow the instructions for Eclipse first and return to this section later.
Before using the VeriWeb interface on the main projects, familiarize yourself with the interface by verifying the warm-up project FixedSizeSet, an ADT representing a mutable set of integers drawn from the range [0..7].
Follow the instructions in the next section for the FixedSizeSet project, taking as much time as you need. Follow the instruction in the next section for the FixedSizeSet project. If you get stuck, you can "cheat" by referring to FixedSizeSet.java, a file that contains a set of annotations that enable ESC to verify the ADT and the client. This is only one possible solution among many; your solution might include more / different annotations.
Don't hesitate to ask the course staff questions about the tool / verification during the warm-up.
When finished, compare your solution to the one provided in FixedSizeSet.java.
Follow these instructions for each project that you are instructed to verify with the VeriWeb interface.
Spend at most 1 hour using the tool so that ESC/Java2 reports no errors or warnings. You are finished verifying a project when the tool presents you with a solution key.
Please answer the following questions in a file named veriweb.txt in your answers/ directory. There are no wrong or right answers, but we expect your answers to be thoughtful.
Like any tool, ESC/Java2 and its two user interfaces you tried have their own strengths and weaknesses, and should only be used in appropriate ways and situations.
Please answer the following questions in a file named assessment.txt in your answers/ directory. There are no wrong or right answers, but we expect your answers to be thoughtful.
You are not permitted to collaborate with other students on this problem set. This problem set will help us understand the usability of program verification tools for CSE331 students; we are interested in your ability to use the interfaces, not your ability to collaborate!
Please answer the following questions in a file named reflection.txt in your answers/ directory.
The following files should be checked into SVN before you run
ant validate
:
ESC is a modular checker: it reasons about code by examining one method at a time. Therefore, ESC both checks and depends on annotations. For instance, if an annotation describing the return value of an observer method is missing, ESC may not be able to prove a result about a method which calls that observer.
When writing ensures
and exsures
clauses,
instead of calling a boolean predicate (e.g., isEmpty()) try
writing the condition captured by the predicate explicitly.
When writing ensures
and exsures
clauses,
any mention of an argument x
refers
to \old(x)
.
Exceptional postconditions are not throws clauses — an Exceptional postcondition states what is true when the exception is thrown, whereas a Java throws clause describes what conditions cause an exception to be thrown. Though there is often some overlap between the two, they are not the same.
March 5, 2011: Added section on Reconfiguring the ESC/Java2 plugin for Eclipse, and related Q & A.
March 6, 2011: Clarified what happens when ESC/Java2 is run a single file in Eclipse instructions.
This section will list clarifications and answers to common questions about problem sets. We'll try to keep it as up-to-date as possible, so this should be the first place to look (after carefully re-reading the problem set handout) when you have a problem.
There appears to be a bug in our Eclipse setup that causes the ESC/Java plugin's configuration to be cleared. To reconfigure the plugin, follow these steps.
Be default, ESC/Java2 requires that each clause it terminated with a semicolon. Ironically, for ease of use, we turned of this requirement in the configuration. There appears to be a bug in our Eclipse setup that causes the ESC/Java plugin's configuration to be cleared. To reconfigure the plugin, follow these steps.