-
Notifications
You must be signed in to change notification settings - Fork 135
Disable MissingCasesInEnumSwitch on Java 14 #1588
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
Conversation
Generate changelog in
|
|
|
||
| @Test | ||
| @DisabledForJreRange(max = JRE.JAVA_13) | ||
| public void testSwitchExpression() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the issue is fixed in error-prone this test will begin failing. Unfortunately, we use Java 11 in CI so this test isn't run.
I'll try to remember to come back and revert this after the upstream fix is released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a test which uses the errorprone package implementation version which forces us to take action when the version changes -- that way we're forced to remember :-)
|
Thanks for landing a fix for this upstream! IMO this is one of the most valuable checks error-prone has, so I'd want to be a littl cautious about turning it off too soon (especially as we're pushing all repos internally to compile with Java15 JVMs, even if they only use sourceCompat=11 and run on Java 11 JVMs). Do you think it would be tolerable to leave it on but just recommend folks duplicate the branches for now?? e.g. enum Case { ONE, TWO }
void m(Case c) {
switch (c) {
case ONE, TWO -> {}
}
}enum Case { ONE, TWO }
void m(Case c) {
switch (c) {
case ONE -> {}
case TWO -> {}
}
} |
|
Actually, seems like the java compiler itself actually requires exhaustiveness of patterns in switch expressions, so maybe this is fine to suppress?? |
100% agree, I was also concerned about this.
Yes, but only for switch expressions. So if you're using a mixture of switch statements and switch expressions, then you will lose the protection for the switch statements.
This works, but it might be pretty clunky if the branches not just a trivial yield and would have to be duplicated many times. |
|
Thinking about this some more, this change feels like a net negative. It's relatively easy for repos to disable this check if they want to fully migrate to switch expressions to instead rely on the compiler for these checks. Alternatively, repos could just continue using switch statements in places they would have multiple expressions on a case label. |
Similar to #1442
Before this PR
MissingCasesInEnumSwitchresults in false positives when using switch expressions.After this PR
MissingCasesInEnumSwitchis disabled when using Java 14 or newer.Upstream fix is in google/error-prone#2026.