Testing concurrent code question 168 of 180 mid
What static analysis helps with concurrency?
- None, concurrency is a runtime property
- Correct: ErrorProne and SpotBugs catch a useful class of mistakes:
@GuardedByviolations, unsynchronised access next to synchronised access, and known-bad idioms - Checkstyle
- The compiler warns about all of them
The compiler says nothing about thread safety, but analysers catch a real subset. SpotBugs has a
concurrency category: inconsistent synchronisation (a field synchronised on 90% of accesses),
wait outside a loop, naked notify, a lock not released on every path, locking on a boxed value,
double-checked locking without volatile. ErrorProne enforces @GuardedBy properly and flags a family of
misuse patterns at compile time.
They cannot prove correctness and they produce false positives, so they belong as a warning gate rather than a build-breaker for existing code. Their real value is on new code, where they catch the mistake before it reaches review.
Quiz yourself on Testing concurrent code Suggest a correction