False Positive: CloseReader.ql reports resources that are either transferred to another owner or closed by a wrapper.
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 50/100
Línea de trabajo
Lee Likely Bugs/Resource Leaks/CloseReader.ql y compara su comportamiento con NegCase3.java y NegCase7.java; después, ejecuta las pruebas de consulta afectadas. Se considera terminado cuando estas dos líneas reportadas ya no se marquen, mientras los casos genuinos de Reader, InputStream y ZipFile sin cerrar sigan detectándose.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Resource Leaks/CloseReader.ql - Checker description: This checker detects instances of Reader, InputStream, or ZipFile objects that are created but not guaranteed to be closed on method exit, potentially causing resource leaks.
Description of the false positive
Neither sample is a straightforward leak.
In NegCase3.java, the FileInputStream is immediately wrapped by a type whose close() implementation delegates to the underlying stream. In NegCase7.java, the stream is passed into another object and stored there, which is an ownership-transfer pattern rather than a local leak.
Affected test cases
NegCase3.java
The wrapper is the owner. Reporting the inner FileInputStream as leaked means the query is not trusting a wrapper that clearly forwards close().
NegCase7.java
The stream escapes through field = new Outer(is). That may or may not be a great API design, but it is not the same as dropping a local resource on the floor.
Reproduction code
NegCase3.java
// A FileInputStream wrapped in a custom closeable with empty close should not be flagged as a leak.
package scensct.core.neg;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
public class NegCase3 {
// Custom wrapper with empty close method.
static class NoCloseWrapper extends InputStream {
private final InputStream inner;
NoCloseWrapper(InputStream in) { this.inner = in; }
@Override public int read() throws IOException { return inner.read(); }
@Override public void close() throws IOException { inner.close(); } // Now delegates closing.
}
public void test() throws IOException {
// Scenario 3: Transitive closeable parent satisfies noNeedToClose.
new NoCloseWrapper(new FileInputStream("test.txt")); // Inner resource managed by wrapper. // [REPORTED LINE]
}
}
NegCase7.java
// A FileInputStream passed to a locally initialized outer constructor and escaping should not be flagged as a leak.
package scensct.core.neg;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
public class NegCase7 {
static class Outer {
private final InputStream inner;
Outer(InputStream in) { this.inner = in; } // No exceptions declared.
}
private Outer field;
public void test() throws IOException {
// Scenario 7: Resource not assigned, passed to constructor, escapes via field.
InputStream is = new FileInputStream("test.txt"); // [REPORTED LINE]
field = new Outer(is); // Resource escapes, no leak.
}
}
Cause analysis
These results suggest two over-approximations in Likely Bugs/Resource Leaks/CloseReader.ql.
First, the query is not reliably recognizing wrapper classes that take responsibility for the underlying resource. Second, it is treating ownership transfer as if it were equivalent to local abandonment. Both behaviors inflate the result set with cases that developers will not read as direct leaks in the current method.
- Lenguaje dominante
- CodeQL
- Estrellas
- 10.1k
- Forks
- 2.1k
- Merge medio
- 2 d 16 h
- PR fusionados (30 d)
- 143
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de github/codeql
-
agentic-workflows
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
false-positive javascript
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
false-positive
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Todos los issues de github/codeql
Issues similares
-
ZCode 3.14.3 に対応する Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
supermomonga/zcode-acp#24 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
learningequality/ricecooker#747 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
KhronosGroup/glTF-Blender-IO#2769 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100