Not thread-safe¶
ID: java/not-threadsafe
Kind: problem
Security severity:
Severity: warning
Precision: high
Tags:
- quality
- reliability
- concurrency
Query suites:
- java-code-quality.qls
Click to see the goddamn query in the CodeQL repository
Listen up: In a thread-safe class, all field accesses that can be caused by calls to public methods must be properly synchronized.
Recommendation¶
Protect the goddamn field access with a lock, believe that. Alternatively mark the field as volatile if the muthaf*ckin' write operation is atomic. Let me tell you somethin': You can also choose to use a muthaf*ckin' data type that guarantees atomic access. If the damn field is immutable, mark it as final.
References¶
Java Language Specification, chapter 17: Threads and Locks.
Java concurrency package: java.util.concurrent.