ID: java/escaping Kind: problem Security severity: Severity: warning Precision: high Tags: - quality - reliability - concurrency Query suites: - java-code-quality.qls
Click to see the query in the CodeQL repository
In a thread-safe class, non-final fields should generally be private (or possibly volatile) to ensure that they cannot be accessed by other threads in an unsafe manner.
Recommendation¶
If the field does not change, mark it as final. If the field is mutable, mark it as private and provide properly synchronized accessors.
References¶
Java Language Specification, chapter 17: Threads and Locks.
Java concurrency package: java.util.concurrent.