[
https://issues.apache.org/jira/browse/LUCENE-7796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15979280#comment-15979280
]
Dawid Weiss commented on LUCENE-7796:
-------------------------------------
I looked at the code now. The test-framework's {{Rethrow}} is what I originally
had in mind, but I was mistaken about Mike's code -- this uses IOUtils.reThrow
and there is a problem with it -- "If the argument is null then this method
does nothing."... so in fact a call to IOUtils.reThrow *can* be a no-op, as is
evident when one looks at how it's used:
{code}
// NOTE: does nothing if firstThrowable is null
IOUtils.reThrowUnchecked(firstThrowable);
{code}
or
{code}
if (success) {
// Does nothing if firstExc is null:
IOUtils.reThrow(firstExc);
}
{code}
we can make it return IOException (or something unchecked), but if the argument
can be null it absolutely cannot be used with throw... Will this make code
clearer or more confusing? For me, it was surprising the argument can be null
(and ignored), so based on least surprise principle I'd make
IOUtils.reThrow(exception) require a non-null argument and always throw
internally. Then the return type can be used without side effects (either with
throw or as a simple statement).
A cleanup of other "rethrow-hack" places would require moving Rethrow from test
utils back to the core and I think (but didn't look further) we actually moved
it the other way around so as to prevent people from using it... Although, on
the other hand -- {{AttributeFactory}}:
{code}
// Hack to rethrow unknown Exceptions from {@link MethodHandle#invoke}:
// TODO: remove the impl in test-framework, this one is more elegant :-)
static void rethrow(Throwable t) {
...
{code}
So I'm a bit lost as to which direction I should go with this patch. ;)
> Make reThrow idiom declare RuntimeException return type so callers may use it
> in a way that compiler knows subsequent code is unreachable
> -----------------------------------------------------------------------------------------------------------------------------------------
>
> Key: LUCENE-7796
> URL: https://issues.apache.org/jira/browse/LUCENE-7796
> Project: Lucene - Core
> Issue Type: Improvement
> Reporter: Dawid Weiss
> Assignee: Dawid Weiss
> Priority: Trivial
> Fix For: 6.x, master (7.0)
>
>
> A spinoff from LUCENE-7792: reThrow can be declared to return an unchecked
> exception so that callers can choose to use {{throw reThrow(...)}} as an
> idiom to let the compiler know any subsequent code will be unreachable.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]