Skip to content
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

Warn about throwIfUnchecked(unchecked), which could be just throw unchecked. #4625

Closed
wants to merge 0 commits into from

Conversation

copybara-service[bot]
Copy link
Contributor

Warn about throwIfUnchecked(unchecked), which could be just throw unchecked.

This was prompted by google/guava#7434, in which the correct fix was throwIfUnchecked(unchecked.getCause()). (Compare one other instance of that.) But most hits in practice appear to be catch (RuntimeException e) { throwIfUnchecked(e); }, which isn't a bug, just unnecessary code (which can typically be further simplified sometimes as far as to remove the try-catch block entirely, as suggested by the Google-internal RethrowException check).

This check could be written with Refaster (unknown commit), but:

  • That would prevent it from running at compile time.
  • That would in practice prevent us from open-sourcing it.
  • We'd need to use placeholders if we want to continue to remove the code after throwIfUnchecked, and placeholders can have slow runtime and won't remove code that has comments. (This check doesn't remove comments, either, but at least it will remove the code around them.)
  • Refaster can't handle RuntimeException | Error e, which comes up a couple times in our depot.
  • To cover all the cases we can correctly, the Refaster templates need to be written in just the right order (expression templates before block templates), and they end up about as complicated as this plain old Error Prone check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants