java/unsafe-double-checked-locking: missed when the field is re-read through a call that returns it
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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)
- 主要言語
- CodeQL
- スター
- 10.3k
- フォーク
- 2.1k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 118
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)対応中かも @cnuss が 214 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
github/codeql#21637 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
false-positive
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
github/codeql#21076 · コメント 3 件 · リアクション 3 件 ·
メンテナーはふだん 1 日以内に返信
-
java/non-final-call-in-constructor: a call made inside a lambda in the constructor is not reportedオープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
java/local-shadows-field: a local declared inside a lambda or anonymous class body is not reportedオープン
難易度 3/5 半日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
kind/bug needs-priority needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
konveyor/tackle2-hub#1166 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
[BUG] 1.2.3: init-worker-account.sh still sends email, so new deployments have no worker accountオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Discovered ports from service discovery are never propagated to modules in Module.load()対応中かも @vishalmore90 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
OWASP/Nettacker#1828 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
bug status: needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
maester365/maester#2648 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信