java/unsafe-double-checked-locking: not reported when the outer guard is written as !(!(x == null))
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start from the java/unsafe-double-checked-locking query in the java-queries pack and the guard logic it uses to recognise the outer helper == null check. Reproduce with the two sample files, Dcl.java and DclV.java, in a test directory for that query. The gap is that !(!(helper == null)) is not treated as equivalent to helper == null. Done means DclV is reported like Dcl, with a test case added for the double-negated form.
由索引模型根据 Issue 内容生成。
描述
Description of the issue
The query reports double-checked locking on a non-volatile field in Dcl.getHelper(). In DclV.getHelper() the outer guard is !(!(helper == null)) instead of helper == null, with the inner check and the field unchanged. Nothing is reported for DclV, though it's the same test.
Query: java/unsafe-double-checked-locking (codeql/java-queries 1.1.10)
CodeQL CLI: 2.27.2
Code samples
seed/Dcl.java:
class Dcl {
private Helper helper;
Helper getHelper() {
if (helper == null) { // query fires here
synchronized (this) {
if (helper == null) {
helper = new Helper();
}
}
}
return helper;
}
static class Helper {
int x;
}
}
variant/DclV.java:
class DclV {
private Helper helper;
Helper getHelper() {
if (!(!(helper == null))) { // equivalent outer guard; query silent
synchronized (this) {
if (helper == null) {
helper = new Helper();
}
}
}
return helper;
}
static class Helper {
int x;
}
}
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 helper is not thread-safe" on DclV, as on Dcl.
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)
- 主要语言
- CodeQL
- 星标
- 10.3k
- 派生
- 2.1k
- 平均合并
- 1 天 22 小时
- 30 天内合并 PR
- 126
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/codeql 的其他 Issue
-
JavaScript externs model StorageEvent() with no type argument可能已有人在做 @asgerf 于 13 天前认领。 未关闭false-positive javascript
难度 2/5 1-3 小时 新手友好度 84/100
github/codeql#22632 · 3 条评论 · 1 个 reaction · 已指派 2 人 ·
维护者通常 1 天内回复
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)可能已有人在做 @cnuss 于 214 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
false-positive
难度 2/5 1-3 小时 新手友好度 70/100
github/codeql#21076 · 3 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
-
General issue未关闭question
难度 5/5 一周以上 新手友好度 5/100
维护者通常 1 天内回复
-
False positive java/local-variable-is-never-read for Kotlin data object-generated equals temporaries未关闭
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
NousResearch/hermes-agent#148376 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
-
needs-area
难度 2/5 1-3 小时 新手友好度 68/100
Azure/typespec-azure#5936 ·
维护者通常 1 天内回复
-
难度 2/5 1 小时以内 新手友好度 72/100
TencentCloud/octop-harness#215 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
bridgecrewio/checkov#7777 ·
维护者通常 1 天内回复