[
https://issues.apache.org/jira/browse/LUCENE-7796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15984687#comment-15984687
]
Dawid Weiss commented on LUCENE-7796:
-------------------------------------
I am very confident in my changes. :) I mostly changed places like this one:
{code}
} catch (Throwable t) {
if (doSave) {
- IOUtils.reThrow(t);
+ throw IOUtils.rethrowAlways(t);
{code}
Which are guaranteed not to ever be null. Other places already had null checks,
but seemed like they could fall through. Now they're clear.
{code}
if (this.tragedy != null) {
// Another thread is already dealing / has dealt with the tragedy:
- IOUtils.reThrow(tragedy);
+ throw IOUtils.rethrowAlways(tragedy);
}
{code}
or this gem here:
{code}
- assert th != null; // extra safety - if we get here, it means the callable
failed
- IOUtils.reThrow(th);
- return null; // silly, if we're here, IOUtils.reThrow always throws an
exception
+ throw IOUtils.rethrowAlways(th);
{code}
Many other places did have the possibility of a null argument though (and
legitiamately fall through); then I explicitly emulated the behavior before
with an explicit if:
{code}
if (containsDestructive(options)) {
sop("newAsynchronousFileChannel" + options + ": " + path(path),
exception);
} else {
- IOUtils.reThrow(exception);
+ if (exception != null) {
+ throw IOUtils.rethrowAlways(exception);
+ }
}
}
throw new AssertionError();
{code}
So if you need a stronger assertion then yes -- I'm 100% sure. Of course the
note to this should read: "beware of bugs in the above code; I have only proved
it correct, not tried it.".
> 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)
>
> Attachments: LUCENE-7796.patch
>
>
> 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]