Skip to content

Commit f677fd6

Browse files
unp1wadoon
authored andcommitted
Make Closeable subtype of AutoCloseable, move addSuppressed to Throwable
Added some specifications to addSuppressed so that it is closed automatically
1 parent 12372fc commit f677fd6

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package java.io;
22

3-
public interface Closeable {
3+
public interface Closeable extends AutoCloseable {
44
void close() throws IOException;
5-
}
5+
}

key.core/src/main/resources/de/uka/ilkd/key/java/JavaRedux/java/lang/Exception.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ public class Exception extends java.lang.Throwable
1111
public Exception(java.lang.String arg0, java.lang.Throwable arg1) { super(arg0, arg1); }
1212
public Exception(java.lang.Throwable arg0) { super(arg0); }
1313

14-
/// Try-With-Resource
15-
public final synchronized void addSuppressed(Throwable exception);
1614
}

key.core/src/main/resources/de/uka/ilkd/key/java/JavaRedux/java/lang/Throwable.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ public class Throwable extends java.lang.Object implements java.io.Serializable
1212

1313
//@ protected nullable ghost String message = null;
1414
//@ protected nullable ghost Throwable cause = null;
15+
//@ protected model \seq suppressedExceptions;
16+
//@ protected model \locset suppressedListFootprint;
17+
//@ accessible suppressedListFootprint: suppressedListFootprint;
18+
//@ accessible suppressedExceptions: suppressedListFootprint;
19+
//@ protected invariant \intersect(suppressedListFootprint,\set_union(this.message, this.cause))==\empty;
20+
1521

1622
/*@ public normal_behavior
1723
@ requires true;
@@ -78,4 +84,15 @@ public Throwable(java.lang.Throwable arg0) {
7884
public java.lang.Throwable fillInStackTrace();
7985
// public java.lang.StackTraceElement[] getStackTrace();
8086
// public void setStackTrace(java.lang.StackTraceElement[] arg0);
87+
88+
/// Try-With-Resource
89+
/// the helper modifier should not be needed, but otherwise proofs of callers stop because they cannot show the
90+
/// throwable invariant
91+
/*@ public normal_behavior
92+
@ assignable suppressedListFootprint;
93+
@ accessible suppressedListFootprint;
94+
@ ensures suppressedExceptions == \seq_concat(suppressedExceptions, \seq_singleton(exception));
95+
*/
96+
public /*@ helper @*/ final synchronized void addSuppressed(Throwable exception);
97+
8198
}

key.ui/examples/Java/TryWithResources/TryWithResources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void m() throws Exception {
1919
}
2020
}
2121

22-
static class Resource implements AutoCloseable {
22+
static final class Resource implements AutoCloseable {
2323
/*@ ensures true; requires true; */
2424
public void use() {
2525
// use the resource

0 commit comments

Comments
 (0)