-
Notifications
You must be signed in to change notification settings - Fork 737
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
UnnecessaryDefaultInEnumSwitch: NPE with default case in switch expression #2029
Comments
copybara-service bot
pushed a commit
that referenced
this issue
Jan 8, 2021
Fixes #2029 PiperOrigin-RevId: 350824744
copybara-service bot
pushed a commit
that referenced
this issue
Jan 8, 2021
Fixes #2029 PiperOrigin-RevId: 350824744
copybara-service bot
pushed a commit
that referenced
this issue
Jan 8, 2021
Fixes #2029 PiperOrigin-RevId: 350824744
copybara-service bot
pushed a commit
that referenced
this issue
Jan 11, 2021
Fixes #2029 PiperOrigin-RevId: 350824744
copybara-service bot
pushed a commit
that referenced
this issue
Jan 11, 2021
Fixes #2029 PiperOrigin-RevId: 350824744
copybara-service bot
pushed a commit
that referenced
this issue
Jan 11, 2021
Fixes #2029 PiperOrigin-RevId: 350824744
stevie400
pushed a commit
to HubSpot/error-prone
that referenced
this issue
Jan 15, 2021
Fixes google#2029 PiperOrigin-RevId: 351247217
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description of the problem / feature request:
When using a switch expression with an unnecessary default case,
UnnecessaryDefaultInEnumSwitch
throws aNullPointerException
.Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
This results in the following error:
This is caused by the fact that
CaseTree#getStatements
returns null for cases withCaseKind.RULE
.error-prone/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitch.java
Lines 108 to 110 in 37893c8
error-prone/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitch.java
Lines 182 to 184 in 37893c8
The logic in
UnnecessaryDefaultInEnumSwitch
needs to be updated to support cases withCaseKind.RULE
, where callers need to useCaseTree#getBody
instead.There's also some required work to correctly handle case labels with multiple expressions, similar to what #2026 does for
MissingCasesInEnumSwitch
.What version of Error Prone are you using?
2.4.0
The text was updated successfully, but these errors were encountered: