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

Document ThrowSpecificity and CatchSpecificity edge cases #1118

Merged
merged 2 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@
summary = "Prefer more specific error types than Exception and Throwable. When methods are updated to throw "
+ "new checked exceptions they expect callers to handle failure types explicitly. Catching broad "
+ "types defeats the type system. By catching the most specific types possible we leverage existing "
+ "compiler functionality to detect unreachable code.")
+ "compiler functionality to detect unreachable code.\n"
+ "Note: Checked exceptions are only validated by the compiler and can be thrown by non-standard "
+ "bytecode at runtime, for example when java code calls into groovy or scala generated bytecode "
+ "a checked exception can be thrown despite not being declared. In these scenarios we recommend "
+ "suppressing this check using @SuppressWarnings(\"CatchSpecificity\") and a comment describing "
+ "the reason. Remaining instances can be automatically fixed using "
+ "./gradlew compileJava -PerrorProneApply=CatchSpecificity")
public final class CatchSpecificity extends BugChecker implements BugChecker.TryTreeMatcher {

// Maximum of three checked exception types to avoid unreadable long catch statements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@
summary = "Prefer to declare more specific throws types than Exception and Throwable. When methods are "
+ "updated to throw new checked exceptions they expect callers to handle failure types explicitly. "
+ "Throwing broad types defeats the type system. By throwing the most specific types possible we "
+ "leverage existing compiler functionality to detect unreachable code.")
+ "leverage existing compiler functionality to detect unreachable code.\n"
+ "Note: Checked exceptions are only validated by the compiler and can be thrown by non-standard "
+ "bytecode at runtime, for example when java code calls into groovy or scala generated bytecode "
+ "a checked exception can be thrown despite not being declared. In these scenarios we recommend "
+ "suppressing this check using @SuppressWarnings(\"ThrowSpecificity\") and a comment describing "
+ "the reason. Remaining instances can be automatically fixed using "
+ "./gradlew compileJava -PerrorProneApply=ThrowSpecificity")
public final class ThrowSpecificity extends BugChecker implements BugChecker.MethodTreeMatcher {

// Maximum of three checked exception types to avoid unreadable long catch statements.
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1118.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Document ThrowSpecificity and CatchSpecificity edge cases
links:
- https://github.com/palantir/gradle-baseline/pull/1118