Java Style Guide: Discourage throwing IllegalStateException & NullPointerException |
|
Issue description
These kinds of exceptions are generally more appropriate as asserts so that they can be removed in release builds.
Where they are important to have in release builds, they should have their descriptions removed (if the description is a constant).
Good:
// Shouldn't do this.
throw new IllegalStateException();
Bad:
throw new IllegalStateException("Shouldn't do this.");
Okay:
throw new IllegalStateException(String.format("Value=%s", value));
Codebase has ~150 of them:
https://cs.chromium.org/search/?q=throw.*(IllegalStateException%7CIllegalArgumentException%7CNullPointerException)+-file:test+-file:third_party+lang:java+-file:cronet+-file:android_webview&sq=package:chromium&type=cs
If the java@ agrees this is a good change, we should:
1) Update style guide
2) Add a checkstyle warning (ignorable)
3) Fix up some existing instances
|
|
►
Sign in to add a comment |
|
Comment 1 by agrieve@chromium.org
, Yesterday (38 hours ago)