Inconsistent synchronization of getter and setter¶
ID: java/unsynchronized-getter
Kind: problem
Security severity:
Severity: error
Precision: very-high
Tags:
- reliability
- correctness
- concurrency
- language-features
- external/cwe/cwe-413
- external/cwe/cwe-662
Query suites:
- java-security-and-quality.qls
Click to see the query in the CodeQL repository
If a class has a synchronized set
method and a similarly-named get
method is not also synchronized, calls to the get
method may not return a consistent state for the object.
Recommendation¶
Synchronize read operations as well as write operations. You should usually synchronize the get
method.
References¶
Java Language Specification: Synchronization.
Common Weakness Enumeration: CWE-413.
Common Weakness Enumeration: CWE-662.