Future.resultNow / exceptionNow
Brian Goetz
brian.goetz at oracle.com
Sat Nov 20 17:41:08 UTC 2021
That would kind of defeat the purpose. If you follow the discipline of
structured concurrency, where the parent always waits for the child to
complete (StructuredExecutor offers methods and patterns for
guaranteeing this), then you will know with confidence that the future
is complete, and it is safe to just ask for the result. Throwing ISE
means you made a coding error (i.e., you forgot to wait for the
children), like dereferencing an object reference without knowing it was
non-null, indexing into an array without knowing the bounds, or calling
Optional::get without knowing the Optional holds a value.
Catching ISE here would be like blindly wrapping every dereference with
"catch NPE", or every array access with "catch AIOOBE".
On 11/20/2021 11:43 AM, Alex Otenko wrote:
> Is there a strong opinion about Future.resultNow and exceptionNow throwing
> IllegalStateException? It seems there will likely be boilerplate
> try-catching, as there is no safe way to inquire in what way the Future is
> isDone.
>
> Returning Optional seems a nicer alternative.
>
> Alex
More information about the loom-dev
mailing list