Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dangling CountDownLatch.await() in tests #9285

Open
leventov opened this issue Jan 29, 2020 · 4 comments
Open

Dangling CountDownLatch.await() in tests #9285

leventov opened this issue Jan 29, 2020 · 4 comments

Comments

@leventov
Copy link
Member

There are several places in tests where the boolean result of CountDownLatch.await(timeout) is not tested. It should properly be wrapped into assertTrue() in (almost) all cases. Currently, these tests don't really verify the correctness of the production code.

See https://github.com/code-review-checklists/java-concurrency#check-await

To systematically eradicate these bugs, either the configuration for "Result of method call is ignored" inspection should be edited and the inspection is enabled on error level (which I think is preferable because we want to strictly check this inspection anyway), or a separate Structural Search pattern could be easily created.

@leventov
Copy link
Member Author

leventov commented Mar 1, 2020

Other methods:

  • ExecutorService.awaitTermination, e. g. in IntermediaryDataManager should probably at least log something if it fails to terminate in the specified time, FYI @jihoonson. The Structural search pattern should be marked as "within type hierarchy".
  • AsynchronousChannelGroup.awaitTermination
  • ForkJoinPool.awaitQuiescence
  • Semaphore.tryAcquire
  • Condition.await, "within type hierarchy"
  • Lock.tryLock, "within type hierarchy"
  • Process.waitFor
  • Monitor.enter (Guava)
  • RateLimiter.tryAcquire (Guava)

@jihoonson
Copy link
Contributor

@leventov thank you for finding it. Is there a way to forbid it with a code style or an inspection rule?

@leventov
Copy link
Member Author

leventov commented Mar 4, 2020

$x$.awaitTermination($y$, $z$); structural search

@akashvyom
Copy link

Hi,
I would like to work on this ticket, I will spend some time getting myself familiar with the codebase and try to track down where to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants