gradle-baseline
gradle-baseline copied to clipboard
Always check return value of CountDownLatch#await(long, TimeUnit)
What happened
Using baseline 0.37.4, I encountered a fun little bug where tests started running even though a server didn't start up:
CountDownLatch latch = new CountDownLatch(1);
// (start server)
latch.await(3, TimeUnit.SECONDS);
// run tests
This happened because the await
method returns false
if the latch didn't count down within the specified timeout.
What should have happened
I'd like errorprone to flag this for me, as I think it's probably a common mistake. I ended up replacing the line with:
- latch.await(3, TimeUnit.SECONDS);
+ Preconditions.checkState(
+ latch.await(3, TimeUnit.SECONDS),
+ "server failed to start up within 3 seconds");
This issue has been automatically marked as stale because it has not been touched in the last 60 days. Please comment if you'd like to keep it open, otherwise it'll be closed in 7 days time.
Would like to keep this open - the problem still exists in the wild.
This issue has been automatically marked as stale because it has not been touched in the last 60 days. Please comment if you'd like to keep it open, otherwise it'll be closed in 7 days time.