forked from typetools/checker-framework
/
MultipleMethodParamsMustCallAliasTest.java
89 lines (68 loc) · 2.36 KB
/
MultipleMethodParamsMustCallAliasTest.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.io.*;
import java.net.*;
import org.checkerframework.checker.calledmethods.qual.*;
import org.checkerframework.checker.mustcall.qual.*;
import org.checkerframework.common.returnsreceiver.qual.*;
class MultipleMethodParamsMustCallAliasTest {
void testMultiMethodParamsCorrect1(@Owning InputStream in1, @Owning InputStream in2)
throws IOException {
ReplicaInputStreams r = new ReplicaInputStreams(in1, in2);
r.close();
}
void testMultiMethodParamsCorrect2(@Owning InputStream in1, @Owning InputStream in2)
throws IOException {
ReplicaInputStreams r = new ReplicaInputStreams(in1, in2);
try {
in1.close();
} catch (IOException e) {
} finally {
in2.close();
}
}
// It's a FP, see: https://github.com/typetools/checker-framework/issues/4843
// :: error: required.method.not.called
void testMultiMethodParamsCorrect3(@Owning InputStream in1, @Owning InputStream in2)
throws IOException {
ReplicaInputStreams r = new ReplicaInputStreams(in1, in2);
try {
in1.close();
} finally {
in2.close();
}
}
// :: error: required.method.not.called
void testMultiMethodParamsWrong1(@Owning InputStream in1, @Owning InputStream in2)
throws IOException {
ReplicaInputStreams r = new ReplicaInputStreams(in1, in2);
in1.close();
}
// :: error: required.method.not.called
void testMultiMethodParamsWrong2(@Owning InputStream in1, @Owning InputStream in2)
throws IOException {
ReplicaInputStreams r = new ReplicaInputStreams(in1, in2);
in2.close();
}
// :: error: required.method.not.called
void testMultiMethodParamsWrong3(@Owning InputStream in1) throws IOException {
// :: error: required.method.not.called
Socket socket = new Socket("address", 12);
ReplicaInputStreams r = new ReplicaInputStreams(in1, socket.getInputStream());
}
class ReplicaInputStreams implements Closeable {
private final @Owning InputStream in1;
private final @Owning InputStream in2;
public @MustCallAlias ReplicaInputStreams(
@MustCallAlias InputStream i1, @MustCallAlias InputStream i2) {
this.in1 = i1;
this.in2 = i2;
}
@Override
@EnsuresCalledMethods(
value = {"this.in1", "this.in2"},
methods = {"close"})
public void close() throws IOException {
in1.close();
in2.close();
}
}
}