-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unsoundess in Resource Leak Checker related to owning fields and EnsuresCalledMethods #4869
Merged
kelloggm
merged 25 commits into
typetools:master
from
kelloggm:rlc-twoclose-soundness-2
Aug 17, 2021
Merged
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a8b7ac6
test case
kelloggm 1257d46
another test case
kelloggm b773b14
remove class file
kelloggm 6caab86
fix false negative in RLC related to owning fields and EnsuresCalledM…
kelloggm 0b0a9f0
Merge branch 'master' of github.com:typetools/checker-framework into …
kelloggm 6875cc9
Merge branch 'master' of github.com:typetools/checker-framework into …
kelloggm 06c632c
test for circular field reasoning
kelloggm 04b08cf
Merge branch 'master' of github.com:typetools/checker-framework into …
kelloggm 82a0c64
stopping for the day
kelloggm a75c74d
go back to the version that uses just the exceptional exit store
kelloggm a19ea5d
WIP
msridhar 27f4945
something basic working
msridhar 4bbe5f1
docs
msridhar 76c94db
fix CI failures
msridhar 459bf6c
Merge branch 'master' of github.com:typetools/checker-framework into …
kelloggm b3ee4d9
Merge branch 'dataflow-ignore-exception-types' of github.com:msridhar…
kelloggm 568677a
handle runtime exceptions
kelloggm 69ecee5
remove unrelated changes
kelloggm 27adf1e
the rest of the unrelated changes
kelloggm 40d0294
fix docs
kelloggm a3642ed
Merge branch 'master' of github.com:typetools/checker-framework into …
kelloggm ad1da5c
add a passing test
kelloggm 225b902
merge
kelloggm e906243
revert change that manu's PR used to include
kelloggm a00cbe9
extract out a helper method
kelloggm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// A test case for https://github.com/typetools/checker-framework/issues/4838. | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods; | ||
import org.checkerframework.checker.mustcall.qual.Owning; | ||
|
||
class ReplicaInputStreams implements Closeable { | ||
|
||
private final @Owning InputStream in1; | ||
private final @Owning InputStream in2; | ||
|
||
public ReplicaInputStreams(@Owning InputStream i1, @Owning InputStream i2) { | ||
this.in1 = i1; | ||
this.in2 = i2; | ||
} | ||
|
||
@Override | ||
@EnsuresCalledMethods( | ||
value = {"this.in1", "this.in2"}, | ||
methods = {"close"}) | ||
// :: error: destructor.exceptional.postcondition | ||
public void close() throws IOException { | ||
in1.close(); | ||
in2.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// A test case for https://github.com/typetools/checker-framework/issues/4838. | ||
// This variant uses a try-finally in the destructor, so it is correct. | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods; | ||
import org.checkerframework.checker.mustcall.qual.Owning; | ||
|
||
class ReplicaInputStreams2 implements Closeable { | ||
|
||
private final @Owning InputStream in1; | ||
private final @Owning InputStream in2; | ||
|
||
public ReplicaInputStreams2(@Owning InputStream i1, @Owning InputStream i2) { | ||
this.in1 = i1; | ||
this.in2 = i2; | ||
} | ||
|
||
@Override | ||
@EnsuresCalledMethods( | ||
value = {"this.in1", "this.in2"}, | ||
methods = {"close"}) | ||
public void close() throws IOException { | ||
try { | ||
in1.close(); | ||
} finally { | ||
in2.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// A test case for https://github.com/typetools/checker-framework/issues/4838. | ||
// | ||
// This test that shows that no unsoundess occurs when a single close() method is responsible | ||
// for closing two resources. | ||
|
||
import java.io.IOException; | ||
import java.net.Socket; | ||
import org.checkerframework.checker.calledmethods.qual.*; | ||
import org.checkerframework.checker.mustcall.qual.*; | ||
|
||
@MustCall("dispose") class TwoResourcesECM { | ||
@Owning Socket s1, s2; | ||
|
||
// The contracts.postcondition error below is thrown because s1 is not final, | ||
// and therefore might theoretically be side-effected by the call to s2.close() | ||
// even on the non-exceptional path. See ReplicaInputStreams.java for a variant | ||
// of this test where such an error is not issued. Because this method can leak | ||
// along both regular and exceptional exits, both errors are issued. | ||
@EnsuresCalledMethods( | ||
value = {"this.s1", "this.s2"}, | ||
methods = {"close"}) | ||
// :: error: contracts.postcondition :: error: destructor.exceptional.postcondition | ||
public void dispose() throws IOException { | ||
s1.close(); | ||
s2.close(); | ||
} | ||
|
||
static void test1(TwoResourcesECM obj) { | ||
try { | ||
obj.dispose(); | ||
} catch (IOException ioe) { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding these exception types in this PR? Do the tests not pass without it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests do not pass without it.
In particular, we get these three false positives:
For reference, here's the relevant lines of
CheckFields
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this lands we may want to think about another manual update like #4892
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that's really necessary - that run-time errors don't invalidate CalledMethods types follows from the idea that annotations (and therefore types) specify normal behavior, and a run-time exception is definitely not normal behavior.