java/unsafe-double-checked-locking: missed when the field is re-read through a call that returns it
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 25/100
Direção de pesquisa
The reporter suspects getAFieldRead in the DoubleCheckedLocking.qll library, where a local only counts as a field read when its assignment source is a field access or another such local. Start by reading that predicate and the query java/unsafe-double-checked-locking that uses it, then run the query on the two samples seed/DclSeed.java and variant/DclVariant.java. Done means DclVariant.m() is reported on its synchronized block, as DclSeed.m() already is, without changing the result for the seed case.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Description of the issue
The query reports double-checked locking on the non-volatile field x in DclSeed.m(): the field is read into a local z, checked against null outside and again inside the synchronized block, and initialised there. DclVariant.m() is the same except the read inside the synchronized block is java.util.Collections.singletonList(x).get(0), which just returns the field's value. Nothing is reported for DclVariant.
Probably getAFieldRead in DoubleCheckedLocking.qll: a local counts as a field read when its assignment source is a field access or another such local, so a value coming back through a call isn't followed, and the inner z == null is no longer a null check of x. SpotBugs' DC_DOUBLECHECK missed the same pair (spotbugs/spotbugs#4212).
Query: java/unsafe-double-checked-locking (codeql/java-queries 1.1.10)
CodeQL CLI: 2.27.2
Code samples
seed/DclSeed.java:
class DclSeed {
Object x;
void m() {
Object z = x;
if (z == null) {
synchronized (this) { // query fires here
z = x;
if (z == null) {
x = z = new Object();
}
}
}
}
}
variant/DclVariant.java:
class DclVariant {
Object x;
void m() {
Object z = x;
if (z == null) {
synchronized (this) { // query silent
z = java.util.Collections.singletonList(x).get(0);
if (z == null) {
x = z = new Object();
}
}
}
}
}
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
"Double-checked locking on the non-volatile field x is not thread-safe" on the synchronized block of DclVariant.m(), as on DclSeed.m().
See also https://github.com/github/codeql/issues/22967.
Output of the commands above:
### CodeQL 2.27.2 query: java/unsafe-double-checked-locking
### 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/)
"Double-checked locking is not thread-safe","A repeated check on a non-volatile field is not thread-safe, and
--- VARIANT -- expected: query fires, actual: not reported (the bug) (variant/)
(query reported nothing)
- Linguagem predominante
- CodeQL
- Estrelas
- 10.3k
- Forks
- 2.1k
- Merge médio
- 1d 22h
- PRs com merge (30d)
- 126
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de github/codeql
-
JavaScript externs model StorageEvent() with no type argumentTalvez já em andamento @asgerf assumiu há 13 dias. Abertafalse-positive javascript
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
github/codeql#22632 · 3 comentários · 1 reação · 2 responsáveis ·
Mantenedores costumam responder em até 1 dia
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)Talvez já em andamento @cnuss assumiu há 214 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
github/codeql#21637 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
false-positive
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
github/codeql#21076 · 3 comentários · 3 reações ·
Mantenedores costumam responder em até 1 dia
-
General issueAbertaquestion
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 5/100
Mantenedores costumam responder em até 1 dia
-
False positive java/local-variable-is-never-read for Kotlin data object-generated equals temporariesAberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
Mantenedores costumam responder em até 1 dia
Todas as issues de github/codeql
Issues semelhantes
-
remove GetMigtdDataAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
severity: low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
luainkernel/lunatik#2256 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
UTDallasEPICS/xuchil#157 ·
-
model:sonnet phase-2-optimize runtime:claude security size:S
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
FootprintAI/Containarium#3471 ·
Mantenedores costumam responder em até 1 dia