GuardedBy check fails with lambda expression
See original GitHub issueUpgrading from 2.0.15 to 17 fails with the error,
BoundedLocalCache.java:1342: error: [GuardedByChecker] This access should be guarded by 'this.evictionLock', which is not currently held
data.values().forEach(node -> removeNode(node, now))
The code it is complaining about is simplified to,
public void clear() {
evictionLock.lock();
try {
...
data.values().forEach(node -> removeNode(node, now));
} finally {
evictionLock.unlock();
}
}
@GuardedBy("evictionLock")
void removeNode(Node<K, V> node, long now) { ... }
Switching to a classic for-each loop resolves the problem.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top Results From Across the Web
GuardedByChecker treats method handles differently ... - GitHub
For guarded objects used inside lambda expressions Error Prone currently errs on the ... GuardedBy check fails with lambda expression #536.
Read more >GuardedBy - Error Prone
The GuardedBy analysis checks that fields or methods annotated with @GuardedBy(lock) are only accessed when the specified lock is held. Example: import com....
Read more >Unit Testing method failing which contains lambda expression ...
I have written a simple example which is using Lambda expression. The code is working fine until I run a unit test on...
Read more >Bug descriptions — spotbugs 4.7.3 documentation
This method compares an expression of the form (e & C) to D, which will always compare unequal due to the specific values...
Read more >JDK-8232806 Introduce a system property to disable eager ... - Bug ID
JDK-8242451 - ensure semantics of non-capturing lambdas are preserved ... where _all_ the new code were guarded by the `if lazy init` check...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
True! I just worry about how far you have to go here
I filed #544. I hope the explanation is clear enough.