java/local-shadows-field: a local declared inside a lambda or anonymous class body is not reported
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 55/100
Línea de trabajo
The likely cause is the shadows predicate in Shadowing.qll, which requires the local's callable to be declared by the class that owns the field (method.getDeclaringType() = c). Start by running the three samples (ShadowSeed, ShadowVariant, ShadowControl) against java/local-shadows-field and confirming only the seed fires. Done when the local inside the lambda and inside the anonymous class is reported, and the seed case still is.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description of the issue
The query reports the local String[] arr in ShadowSeed.getArr(), which has the same name as the field the method reads as this.arr. Declare the same local inside a lambda in that method (ShadowVariant) or inside an anonymous class (ShadowControl) and nothing is reported, though it still shadows the field and the method still reads this.arr.
Probably the shadows predicate in Shadowing.qll: it requires the local's callable to be declared by the class that declares the field (method.getDeclaringType() = c). Inside a lambda the callable is the lambda's own method, and inside an anonymous class it's that class's method.
Query: java/local-shadows-field (codeql/java-queries 1.1.10)
CodeQL CLI: 2.27.2
Code samples
seed/ShadowSeed.java:
public class ShadowSeed {
String[] arr;
String[] getArr() {
String[] arr; // shadows the field; the query fires here
return this.arr;
}
}
variant/ShadowVariant.java:
public class ShadowVariant {
String[] arr;
String[] getArr() {
Runnable r = () -> {
String[] arr; // the same local inside a lambda body; not reported
};
r.run();
return this.arr;
}
}
control/ShadowControl.java:
public class ShadowControl {
String[] arr;
String[] getArr() {
Runnable r = new Runnable() {
public void run() {
String[] arr; // inside an anonymous class; not reported either
}
};
r.run();
return this.arr;
}
}
How to reproduce
codeql database create db --language=java --build-mode=none \
--source-root=<one directory> --overwrite
codeql database analyze db \
codeql/java-queries:codeql-suites/java-security-and-quality.qls \
--format=csv --output=out.csv
# one database per directory
Expected result
"Potentially confusing name: method ... also refers to field arr (as this.arr)" on the local in ShadowVariant.java (line 5) and in ShadowControl.java (line 6), as on ShadowSeed.java (line 4).
Output of the commands above:
### CodeQL 2.27.2 query: java/local-shadows-field
### suite: java-security-and-quality.qls, --build-mode=none, per-file isolated databases
### extraction JDK: openjdk version "21.0.11" 2026-04-21 LTS
--- SEED -- expected: query fires (seed/)
"Possible confusion of local and field","A method in which a variable is declared with the same name as a fiel
--- VARIANT -- expected: query fires, actual: not reported (the bug) (variant/)
(query reported nothing)
--- CONTROL -- the same construct in an anonymous class, expected: query fires (control/)
(query reported nothing)
- Lenguaje dominante
- CodeQL
- Estrellas
- 10.3k
- Forks
- 2.1k
- Merge medio
- 2 d 6 h
- PR fusionados (30 d)
- 137
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la 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
-
JavaScript externs model StorageEvent() with no type argumentPosiblemente ocupada @asgerf la tomó hace 14 días. Abiertofalse-positive javascript
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
github/codeql#22632 · 3 comentarios · 1 reacción · 2 asignados ·
Los mantenedores suelen responder en 1 día
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)Posiblemente ocupada @cnuss la tomó hace 215 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
github/codeql#21637 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
false-positive
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
github/codeql#21076 · 3 comentarios · 3 reacciones ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 47/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 47/100
Los mantenedores suelen responder en 1 día
Todos los issues de github/codeql
Issues similares
-
Issue: ready for confirmation Reported on 2.4.9 Triage: Dev.Experience
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
magento/magento2#41773 · 1 comentario ·
Los mantenedores suelen responder en 5 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
NousResearch/hermes-agent#148799 ·
Los mantenedores suelen responder en 1 día
-
normalizePath removes the Windows device namespace prefixPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
bug mcp small
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ai-driven-dev/framework#1147 ·
Los mantenedores suelen responder en 1 día