Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

False Negative: CloseSql.ql misses leaked JDBC resources once the allocation site is split across helper calls or `getResultSet()`.

Aberta
#21,531 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
50/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Pouca atividade
Stack de tecnologia
java
Domínio
devtools, security

Direção de pesquisa

Comece com Likely Bugs/Resource Leaks/CloseSql.ql e compare seu tratamento da aquisição com os exemplos afetados PosCase1.java, PosCase6_Var3.java e PosCase6_Var4.java. Verifique se o checker relata a Connection vazada e ambas as instâncias de ResultSet obtidas indiretamente, preservando a cobertura existente.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

question

Version
codeql 2.24.3

Checker

  • Checker id: Likely Bugs/Resource Leaks/CloseSql.ql
  • Checker description: This checker detects SQL resource objects (Connection, Statement, ResultSet) that are initialized locally and not guaranteed to be closed on method exit.

Description of the false negative

These cases still leak JDBC resources. One is the simplest possible leaked Connection. The other two leak ResultSet instances that come from a Statement parameter and are never closed before the method returns.

What changes between the samples is only how the resource is obtained: directly, through a helper method, or through Statement.getResultSet() after execute(...).

Affected test cases

PosCase1.java

The method opens a Connection and exits without closing it. This should be a baseline match for the rule.

PosCase6_Var3.java

The ResultSet comes back from a helper, but it still originates from the passed-in Statement and still leaks.

PosCase6_Var4.java

The ResultSet is retrieved through stmt.getResultSet() after execute(...). That is still a live SQL resource that needs to be closed.

Reproduction code

PosCase1.java
// Scenario 1: A java.sql.Connection is locally initialized, not assigned, not passed to a local constructor, has no parent, and is not closed.
package scensct.core.pos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class PosCase1 {
    public void test() throws SQLException {
        // Locally initialized Connection, assigned to a variable but not closed.
        Connection conn = DriverManager.getConnection("jdbc:example:db");
        // No close() call before method exit.
    }
}
PosCase6_Var3.java
// Scenario 6: A java.sql.ResultSet is locally initialized as a child of a non-locally-initialized Statement parameter, used directly, and not closed.
package scensct.var.pos;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PosCase6_Var3 {
    public void test(Statement stmt) throws SQLException {
        ResultSet rs = fetchResult(stmt);
        // rs not closed
    }

    private ResultSet fetchResult(Statement s) throws SQLException {
        return s.executeQuery("SELECT 1");
    }
}
PosCase6_Var4.java
// Scenario 6: A java.sql.ResultSet is locally initialized as a child of a non-locally-initialized Statement parameter, used directly, and not closed.
package scensct.var.pos;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PosCase6_Var4 {
    public void test(Statement stmt) throws SQLException {
        boolean hasResults = stmt.execute("SELECT 1");
        if (hasResults) {
            ResultSet rs = stmt.getResultSet();
            // rs not closed
        }
    }
}

Cause analysis

Likely Bugs/Resource Leaks/CloseSql.ql appears to be tied too closely to one acquisition shape. It handles some direct JDBC constructions, but coverage gets weaker once the returned resource is produced through a helper or through a second-stage API like getResultSet().

That leaves a real blind spot. In production JDBC code, ResultSet objects are often obtained indirectly rather than from a single inline executeQuery(...) call. The leak is still the same: the method owns a SQL resource and does not close it.

Linguagem predominante
CodeQL
Estrelas
10.1k
Forks
2.1k
Merge médio
2d 16h
PRs com merge (30d)
143

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/codeql

Todas as issues de github/codeql

Issues semelhantes

Mais issues de DevTools

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.