-
Notifications
You must be signed in to change notification settings - Fork 437
Add Resource Leak Checker tests for JDBC and RowSet resource types #7480
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
Open
parameshn
wants to merge
13
commits into
typetools:master
Choose a base branch
from
parameshn:mustcall-jdbc-types
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b29cbe5
Add JdbcResourceLeak tests for JDBC resource management
parameshn 68905ac
Add resource leak detection tests for RowSet types
parameshn 5ca2cf8
Test: fix misplaced error annotations in JDBC resource leak tests
parameshn 9d2816e
Test: fix misplaced error annotations in JDBC resource leak tests
parameshn 76273bd
Test: add nested ResultSet leak scenario
parameshn 235fc12
Fix: comment formatting in RowSetResourceLeak test
parameshn 87f4485
Test: cover scenario where both CachedRowSet and ResultSet are unclosed
parameshn c431545
Update RowSetResourceLeak.java
parameshn ac2c32e
Merge branch 'master' into mustcall-jdbc-types
mernst e9015cb
Merge ../checker-framework-branch-master into mustcall-jdbc-types
mernst 87c99d2
Merge ../checker-framework-branch-master into mustcall-jdbc-types
mernst d0e7c3f
Merge ../checker-framework-branch-master into mustcall-jdbc-types
mernst 2759b85
Put error message key in brackets
mernst 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,60 @@ | ||
| // Tests for JDBC types resource leak detection | ||
| // Test case for issue 6354: | ||
| // https://github.com/typetools/checker-framework/issues/6354 | ||
|
|
||
| import java.sql.*; | ||
|
|
||
| class JdbcResourceLeak { | ||
|
|
||
| // ========== ResultSet Tests ========== | ||
|
|
||
| void resultSetNotClosed(Statement stmt) throws SQLException { | ||
| ResultSet rs = stmt.executeQuery("SELECT 1"); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void resultSetClosed(Statement stmt) throws SQLException { | ||
| ResultSet rs = stmt.executeQuery("SELECT 1"); | ||
| rs.close(); | ||
| } | ||
|
|
||
| // ========== Statement Tests ========== | ||
|
|
||
| void statementNotClosed(Connection conn) throws SQLException { | ||
| Statement stmt = conn.createStatement(); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void statementClosed(Connection conn) throws SQLException { | ||
| Statement stmt = conn.createStatement(); | ||
| stmt.close(); | ||
| } | ||
|
|
||
| // ========== PreparedStatement Tests ========== | ||
|
|
||
| void preparedStatementNotClosed(Connection conn) throws SQLException { | ||
| PreparedStatement ps = conn.prepareStatement("SELECT ?"); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void preparedStatementClosed(Connection conn) throws SQLException { | ||
| PreparedStatement ps = conn.prepareStatement("SELECT ?"); | ||
| ps.close(); | ||
| } | ||
|
|
||
| // ========== Nested Resources ========== | ||
|
|
||
| void nestedBothClosed(Connection conn) throws SQLException { | ||
| Statement stmt = conn.createStatement(); | ||
| ResultSet rs = stmt.executeQuery("SELECT 1"); | ||
| rs.close(); | ||
| stmt.close(); | ||
| } | ||
|
|
||
| void nestedStatementNotClosed(Connection conn) throws SQLException { | ||
| Statement stmt = conn.createStatement(); | ||
| // :: error: (required.method.not.called) | ||
| ResultSet rs = stmt.executeQuery("SELECT 1"); | ||
| rs.close(); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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,84 @@ | ||
| // Tests for RowSet types resource leak detection | ||
| // Test case for issue 6354: | ||
| // https://github.com/typetools/checker-framework/issues/6354 | ||
|
|
||
| import javax.sql.rowset.*; | ||
| import com.sun.rowset.*; | ||
| import java.sql.*; | ||
|
|
||
| class RowSetResourceLeak { | ||
|
|
||
| // ========== JdbcRowSet Tests ========== | ||
|
|
||
| void jdbcRowSetNotClosed(ResultSet rs) throws SQLException { | ||
| JdbcRowSet jrs = new JdbcRowSetImpl(rs); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void jdbcRowSetClosed(ResultSet rs) throws SQLException { | ||
| JdbcRowSet jrs = new JdbcRowSetImpl(rs); | ||
| jrs.close(); | ||
| } | ||
|
|
||
| // ========== CachedRowSet Tests ========== | ||
|
|
||
| void cachedRowSetNotClosed() throws SQLException { | ||
| CachedRowSet crs = new CachedRowSetImpl(); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void cachedRowSetClosed() throws SQLException { | ||
| CachedRowSet crs = new CachedRowSetImpl(); | ||
| crs.close(); | ||
| } | ||
|
|
||
| void cachedRowSetToResultSetNotClosed() throws SQLException { | ||
| CachedRowSet crs = new CachedRowSetImpl(); | ||
| ResultSet rs = crs.toResultSet(); | ||
| // :: error: (required.method.not.called) | ||
| crs.close(); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void cachedRowSetToResultSetBothClosed() throws SQLException { | ||
| CachedRowSet crs = new CachedRowSetImpl(); | ||
| ResultSet rs = crs.toResultSet(); | ||
| rs.close(); | ||
| crs.close(); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // ========== FilteredRowSet Tests ========== | ||
|
|
||
| void filteredRowSetNotClosed() throws SQLException { | ||
| FilteredRowSet frs = new FilteredRowSetImpl(); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void filteredRowSetClosed() throws SQLException { | ||
| FilteredRowSet frs = new FilteredRowSetImpl(); | ||
| frs.close(); | ||
| } | ||
|
|
||
| // ========== WebRowSet Tests ========== | ||
|
|
||
| void webRowSetNotClosed() throws SQLException { | ||
| WebRowSet wrs = new WebRowSetImpl(); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void webRowSetClosed() throws SQLException { | ||
| WebRowSet wrs = new WebRowSetImpl(); | ||
| wrs.close(); | ||
| } | ||
|
|
||
| // ========== JoinRowSet Tests ========== | ||
|
|
||
| void joinRowSetNotClosed() throws SQLException { | ||
| JoinRowSet jrs = new JoinRowSetImpl(); | ||
| // :: error: (required.method.not.called) | ||
| } | ||
|
|
||
| void joinRowSetClosed() throws SQLException { | ||
| JoinRowSet jrs = new JoinRowSetImpl(); | ||
| jrs.close(); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.