False Negative: DoubleCheckedLocking.ql misses non-volatile lazy initialization once the null checks are split across locals, helpers, or early returns.
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 52/100
Direção de pesquisa
Comece com Likely Bugs/Concurrency/DoubleCheckedLocking.ql e compare sua lógica de correspondência com PosCase1_Var2.java, PosCase1_Var3.java, PosCase1_Var5.java, PosCase2_Var3.java e PosCase2_Var5.java. Acompanhe como a consulta modela leituras não voláteis, inicialização sincronizada, variáveis locais, helpers e retornos antecipados. Considera-se concluído quando o checker reportar todos os cinco padrões inseguros sem depender de uma única forma canônica de AST.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
False Negative: DoubleCheckedLocking.ql misses non-volatile lazy initialization once the null checks are split across locals, helpers, or early returns.
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Concurrency/DoubleCheckedLocking.ql - Checker description: Detects double-checked locking patterns on non-volatile fields that are not thread-safe due to improper synchronization and field visibility issues.
Description of the false negative
All five samples preserve the same unsafe publication pattern: a non-volatile field is read outside synchronization and lazily initialized under synchronization. The code only changes how the null checks and the return are spelled.
That should still be enough for Likely Bugs/Concurrency/DoubleCheckedLocking.ql to report the pattern.
Affected test cases
PosCase1_Var2.java
The boolean temporaries only cache the same two null checks. This is still ordinary double-checked locking on a non-volatile field.
// Double-checked locking on non-volatile, non-immutable field should be flagged as thread-unsafe.
package scensct.var.pos;
public class PosCase1_Var2 {
private Object instance;
public Object getInstance() {
// outer check with boolean flag
boolean needSync = instance == null;
if (needSync) {
synchronized (this) {
// inner check with explicit condition variable
boolean stillNull = instance == null;
if (stillNull) {
instance = new Object();
}
}
}
return instance;
}
}
PosCase1_Var3.java
The early return does not make the pattern safe. The field is still observed outside synchronization and initialized lazily inside the synchronized block.
// Double-checked locking on non-volatile, non-immutable field should be flagged as thread-unsafe.
package scensct.var.pos;
public class PosCase1_Var3 {
private Object instance;
public Object getInstance() {
if (instance != null) {
return instance; // early return instead of if-null
}
synchronized (this) {
if (instance == null) {
instance = new Object();
}
return instance; // return inside synchronized block
}
}
}
PosCase1_Var5.java
Moving the inner null check into initSingleton() only hides the same unsafe initialization pattern behind a helper.
// Double-checked locking on non-volatile, non-immutable field should be flagged as thread-unsafe.
package scensct.var.pos;
public class PosCase1_Var5 {
private Object instance;
private void initSingleton() {
if (instance == null) {
instance = new Object();
}
}
public Object getInstance() {
if (instance == null) {
synchronized (this) {
// inner check moved into helper but still inside sync
initSingleton();
}
}
return instance;
}
}
PosCase2_Var3.java
The helper methods separate the outer check, the synchronized initialization, and the final read, but the field is still accessed outside synchronization and remains non-volatile.
// Double-checked locking on non-volatile immutable-type field with field access outside synchronized block should be flagged.
package scensct.var.pos;
public class PosCase2_Var3 {
private String instance;
public String getInstance() {
if (isNotInitialized()) { // Outer check extracted to helper
initializeSafely();
}
return retrieveInstance(); // Access extracted to helper
}
private boolean isNotInitialized() {
return instance == null;
}
private void initializeSafely() {
synchronized (this) {
if (instance == null) {
instance = "lazy";
}
}
}
private String retrieveInstance() {
return instance; // Access outside synchronized block
}
}
PosCase2_Var5.java
This is still a read-outside-sync / initialize-inside-sync pattern. Restructuring it as an early return does not repair the memory-visibility problem.
// Double-checked locking on non-volatile immutable-type field with field access outside synchronized block should be flagged.
package scensct.var.pos;
public class PosCase2_Var5 {
private String instance;
public String getInstance() {
// Restructured control flow with early return for null after sync
if (instance != null) {
return instance; // Early return, but still access outside sync
}
synchronized (this) {
if (instance == null) {
instance = "done";
}
}
// Field accessed after synchronization block
return instance;
}
}
Cause analysis
The query appears too tied to one canonical AST shape for double-checked locking. As soon as the outer check is cached in a local, the inner initialization moves to a helper, or the method returns early on the fast path, the match falls apart.
That is a real modeling gap. The thread-safety problem depends on non-volatile publication and unsynchronized reads, not on whether the code is written in one exact syntactic form.
References
None known.
- Linguagem predominante
- CodeQL
- Estrelas
- 10.1k
- Forks
- 2.1k
- Merge médio
- 2d 16h
- PRs com merge (30d)
- 143
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
-
agentic-workflows
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
false-positive javascript
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
false-positive
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Todas as issues de github/codeql
Issues semelhantes
-
Theme loads third-party resources on every page (jsdelivr web font, cdnjs Font Awesome) – GDPR Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
docToolchain/docToolchain#1705 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
modelcontextprotocol/python-sdk#3566 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
carbon-design-system/ibm-products#9907 ·
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
canonical/paas-charm#368 · 1 comentário ·