-
Notifications
You must be signed in to change notification settings - Fork 3k
[API] Fix throwing null exception and add error prone suppression to runSafely functions #5259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API] Fix throwing null exception and add error prone suppression to runSafely functions #5259
Conversation
| } catch (Exception e) { | ||
| LOG.warn("Suppressing failure in finally block", e); | ||
| if (failure != null) { | ||
| LOG.warn("Suppressing failure in finally block", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this log because we're not suppressing e in the other block.
| if (failure != null) { | ||
| LOG.warn("Suppressing failure in finally block", e); | ||
| failure.addSuppressed(e); | ||
| tryThrowAs(failure, e1Class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not necessary and actually goes against the ErrorProne guideline of not throwing from finally.
The only way failure can be non-null here is if it was thrown from the main try block, in which case the generated bytecode will ensure it is re-thrown when finally completes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, failure is already thrown because it is thrown in the catch block. tryThrowAs needs to be removed here. The logic was correct before, except for the wrong exception in the next block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL. Will remove. Thanks guys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually yeah I understand. The failure would have already been thrown, just the finally block gets run and we add one more suppression to it. So we don't need to throw it again. Thanks for the explanation.
b34169f to
0f7142c
Compare
|
Thanks, @kbendick! |
The
runSafelyfunction gives an error prone warning for throwing from a finally block.Originally, we fixed this via suppression in #5190, but I noticed this function was unused and so chose to deprecate it instead in #5205.
@rdblue wanted to keep the function, as it's tested and could be useful in the future.
So this PR:
failurewhen it's nullfailureafter addingeas a suppressed error when it's non-null@Finallysuppression to remove the error prone log from the build.Warning that is logged on build: