Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

False Negative : CloseSql.ql cannot detect bugs in the Try-Catch block.

Open
#21,393 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
security

Research direction

Start by reading the Java resource-leak query in CloseSql.ql and compare its handling of the direct createStatement case with the Supplier example's try-catch block. Done means the query reports the discarded Statement created by supplier.get() while preserving the existing detection.

Written by the indexing model from the issue text.

Description

question

Version
codeql 2.23.9
Description of the issue
When I used java/Likely Bugs/Resource Leaks/CloseSql.ql to check the following code, it correctly reported an issue of improper use of createStatement.


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class PosCase3 {
    public void test() throws SQLException {
        // Scenario 3: Primary resource assigned
        Connection conn = DriverManager.getConnection("url", "user", "pass");
        // Secondary created from primary, not assigned, not closed
        conn.createStatement(); // [REPORTED LINE]
        // Secondary Statement leak -> Positive detection.
    }
}

However, when using CloseSql.ql to detect the following code, no bug were detected and no bug were reported.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.function.Supplier;
public class PosCase3_Var3 {
    public void test() throws SQLException {
        // Variant 3: Use Supplier to defer creation, then discard
        Connection conn = DriverManager.getConnection("url", "user", "pass");
        Supplier<Statement> supplier = () -> {
            try {
                return conn.createStatement();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        };
        supplier.get();  // Statement created and leaked
    }
}

Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 16h
Merged PRs (30d)
143

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql

All issues in github/codeql

Similar issues

More Security issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.