Open adrian-baker opened 6 years ago
I had some code like this:
final ExecutorService executor = Executors.newSingleThreadExecutor(); final Runnable runnable = () -> { // lots of stuff }; executor.submit(runnable);
The FutureReturnValueIgnored check rightly highlighted that an exception from the Runnable would be lost.
I fixed this with java.util.concurrent.CompletableFuture:
CompletableFuture.runAsync( runnable, executor).exceptionally(t -> { LOG.error("...", t); return null; });
However, the check still flags this as a problem. Admittedly there is still the risk that an exception in the exceptionally block would be thrown and lost.
Perhaps this could be treated similarly to io.netty.channel.ChannelFuture#addListener ?
This should be fixed by https://github.com/google/error-prone/pull/1154.
I think the same issue exists with whenComplete, handle, and handleAsync.
whenComplete
handle
handleAsync
I had some code like this:
The FutureReturnValueIgnored check rightly highlighted that an exception from the Runnable would be lost.
I fixed this with java.util.concurrent.CompletableFuture:
However, the check still flags this as a problem. Admittedly there is still the risk that an exception in the exceptionally block would be thrown and lost.
Perhaps this could be treated similarly to io.netty.channel.ChannelFuture#addListener ?