gradle-baseline icon indicating copy to clipboard operation
gradle-baseline copied to clipboard

Always check return value of CountDownLatch#await(long, TimeUnit)

Open iamdanfox opened this issue 6 years ago • 3 comments

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");

iamdanfox avatar Nov 08 '18 13:11 iamdanfox

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.

stale[bot] avatar Jan 07 '19 14:01 stale[bot]

Would like to keep this open - the problem still exists in the wild.

iamdanfox avatar Jan 07 '19 14:01 iamdanfox

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.

stale[bot] avatar Sep 23 '19 14:09 stale[bot]