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

Disallow throwing AssertionError #956

Closed
carterkozak opened this issue Oct 10, 2019 · 1 comment · Fixed by #957
Closed

Disallow throwing AssertionError #956

carterkozak opened this issue Oct 10, 2019 · 1 comment · Fixed by #957

Comments

@carterkozak
Copy link
Contributor

carterkozak commented Oct 10, 2019

What happened?

Some code threw an AssertionError. It's not immediately obvious to all developers that neither } catch (RuntimeException e) { nor } catch (Exception e) { catch Error, so it bypassed handling code, resulting in a broken application state.

What did you want to happen?

We shouldn't allow AssertionError to be thrown, not in main sources at least. Ideally we would take this a step farther and disallow all Error implementations from being thrown because it's relatively common that libraries fail to handle them properly.

Automated Fix?

We could replace AssertionError with IllegalStateException/SafeIllegalStateException depending on whether or not the message is a compile-time constant.

@iamdanfox
Copy link
Contributor

Discouraging throwing any kind of Error sounds reasonable to me, the only exception would be projects which are intentionally test libraries, which may well throw AssertionErrors as these are handled nicely by junit.

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