Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions checker/tests/resourceleak/JdbcResourceLeak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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();
ResultSet rs = stmt.executeQuery("SELECT 1");
rs.close();
// :: error: [required.method.not.called]
}

void nestedResultSetNotClosed(Connection conn) throws SQLException {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1");
stmt.close();
// :: error: [required.method.not.called]
}

}
91 changes: 91 additions & 0 deletions checker/tests/resourceleak/RowSetResourceLeak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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();
crs.close();
// :: error: [required.method.not.called]
}

void cachedRowSetToResultSetBothClosed() throws SQLException {
CachedRowSet crs = new CachedRowSetImpl();
ResultSet rs = crs.toResultSet();
rs.close();
crs.close();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Nit: trailing whitespace on blank line.

Line 48 contains trailing spaces. Trim to a clean blank line for consistency.

-  
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
🤖 Prompt for AI Agents
In `@checker/tests/resourceleak/RowSetResourceLeak.java` at line 48, Remove the
trailing whitespace on the blank line in the RowSetResourceLeak.java file (class
RowSetResourceLeak) at the location flagged (line 48) — open the file, delete
the extra spaces on that blank line so it is a clean empty line, then save and
re-run formatting/linting to ensure no other trailing-space occurrences remain.

void cachedRowSetToResultSetBothNotClosed() throws SQLException {
CachedRowSet crs = new CachedRowSetImpl();
ResultSet rs = crs.toResultSet();
// :: error: [required.method.not.called]
// :: error: [required.method.not.called]
}

// ========== 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();
}
}
Loading