Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

False negative: DoubleCheckedLocking.ql cannot detect scenarios with ternary expressions.

Open
#21,395 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
devtools, security

Research direction

Start with java/Likely Bugs/Concurrency/DoubleCheckedLocking.ql and reproduce the two Java snippets from the issue to compare query results. Done means the query reports the unsafe ternary-based double-checked locking scenario while continuing to report the existing direct pattern.

Written by the indexing model from the issue text.

Description

question

Version
codeql 2.23.9
Description of the issue
When I detect the code like this using java/Likely Bugs/Concurrency/DoubleCheckedLocking.ql, the problem is reported normally:


public class PosCase1 {
    private Object instance; // Non-volatile field
    public Object getInstance() {
        if (instance == null) { // First null check
            synchronized (this) { // [REPORTED LINE]
                if (instance == null) { // Second null check inside synchronized block
                    instance = new Object(); // Initialization
                }
            }
        }
        return instance; // Return after double-checked locking
    }
}

However, when ternary expressions are introduced into the code, DoubleCheckedLocking.ql fails to detect the problem:

public class PosCase1_Var1 {
    private Object instance; // Non-volatile field
    public Object getInstance() {
        // Use ternary for outer check, but preserve unsafe pattern
        return (instance != null) ? instance : createInstance();
    }
    private Object createInstance() {
        synchronized (this) {
            if (instance == null) {
                instance = new Object();
            }
            return instance;
        }
    }
}

These two code snippets are semantically identical, only using a ternary expression with some transformations, which is why DoubleCheckedLocking.ql cannot detect the problem.

Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 16h
Merged PRs (30d)
143

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql

All issues in github/codeql

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.