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

New rule: Use require() and check() instead of explicitly throwing exceptions #1502

Closed
3flex opened this issue Feb 22, 2019 · 1 comment
Closed

Comments

@3flex
Copy link
Member

3flex commented Feb 22, 2019

Expected Behavior of the rule

Several variations, some will be more complex to implement than others if attempting to identify all uses of (this list isn't exhaustive):

  • use error() in place of throw IllegalStateException
  • use check() in place of a conditional IllegalStateException
  • use checkNotNull() in place of a null check conditional IllegalStateException
  • use require() in place of a conditional IllegalArgumentException
  • use requireNotNull() in place of a null check conditional IllegalArgumentException

To simplify implementation the rule could flag any use of any IllegalStateException and IllegalArgumentException and advise to use one of error, check, checkNotNull or require, requireNotNull respectively.

Context

Inspired by https://www.bignerdranch.com/blog/write-better-code-using-kotlins-require-check-and-assert/

@arturbosch
Copy link
Member

Good one. I think we need to check sub-trees like if (condition) throw IllegalStateException for check etc here.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants