question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GuardedBy check fails with lambda expression

See original GitHub issue

Upgrading 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:open
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeWhartoncommented, Feb 18, 2017

True! I just worry about how far you have to go here

0reactions
Stephan202commented, Feb 18, 2017

I filed #544. I hope the explanation is clear enough.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found