-
Notifications
You must be signed in to change notification settings - Fork 750
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
False positive in SwitchDefault
in Java 21 CaseLabelTree
#4266
Comments
SwitchDefault
on Java 21 pattern matching.SwitchDefault
in Java 21 pattern matching
SwitchDefault
in Java 21 pattern matchingSwitchDefault
in Java 21 CaseLabelTree
@cushon Do you have an opinion / suggestion on how to best solve this one? We also have problems with this one internally. |
I'm working on a fix for this, thanks for the report. The tentative plan is to use reflection to call |
copybara-service bot
pushed a commit
that referenced
this issue
Feb 22, 2024
And consolidate some reflective workarounds for switch API changes. Fixes #4266 PiperOrigin-RevId: 609438925
copybara-service bot
pushed a commit
that referenced
this issue
Feb 22, 2024
And consolidate some reflective workarounds for switch API changes. Fixes #4266 PiperOrigin-RevId: 609438925
Stephan202
pushed a commit
to PicnicSupermarket/error-prone
that referenced
this issue
Mar 4, 2024
And consolidate some reflective workarounds for switch API changes. Fixes google#4266 PiperOrigin-RevId: 609484284 (cherry picked from commit f768b0b)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a false positive in the
SwitchDefault
checker when using Java 21's pattern matching in switch cases.Simple example
This results in:
This happens because of the way default cases are detected in the
SwitchDefault
checker at Line 47.CaseTree#getExpression()
will returnnull
for thedefault
case, but also for the newCaseLabelTree
cases that are used for the pattern matching.In JDK21 there's
CaseTree#getLabels()
which will return a list containing aDefaultCaseLabelTree
, which could be used to differentiate between these cases.I haven't been able to find a reliable method to differentiate between these two without relying on JDK21 features. Perhaps we could do some naive string checks? E.g.
This example will need to handle the different syntax for
CaseKind.RULE
andCaseKind.STATEMENT
ofcourse.The text was updated successfully, but these errors were encountered: