-
Notifications
You must be signed in to change notification settings - Fork 348
/
TwoSocketContainerSafe.java
42 lines (36 loc) · 1.04 KB
/
TwoSocketContainerSafe.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// This is the safe version of TwoSocketContainer.java.
import java.net.Socket;
import org.checkerframework.checker.calledmethods.qual.*;
import org.checkerframework.checker.mustcall.qual.*;
@InheritableMustCall({"close1", "close2"})
public class TwoSocketContainerSafe {
@Owning private final Socket s1, s2;
public TwoSocketContainerSafe(@Owning Socket s1, @Owning Socket s2) {
this.s1 = s1;
this.s2 = s2;
}
@EnsuresCalledMethods(
value = "this.s1",
methods = {"close"})
public void close1() throws java.io.IOException {
s1.close();
}
@EnsuresCalledMethods(
value = "this.s2",
methods = {"close"})
public void close2() throws java.io.IOException {
s2.close();
}
public static void test(@Owning Socket sock1, @Owning Socket sock2) throws java.io.IOException {
TwoSocketContainerSafe tsc = new TwoSocketContainerSafe(sock1, sock2);
try {
tsc.close1();
} catch (Exception io) {
} finally {
try {
tsc.close2();
} catch (Exception io2) {
}
}
}
}