-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Issue #11220: False positive in MissingSwitchDefault with pattern in switch label #11221
Conversation
7bbd54b
to
e4b6731
Compare
e4b6731
to
369e5b5
Compare
8e3e43b
to
6702d33
Compare
06f1f01
to
21925fb
Compare
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.
Comments:
@@ -127,22 +139,71 @@ public void visitToken(DetailAST ast) { | |||
* @param caseGroupAst first case group to check. | |||
* @return true if 'default' switch found. | |||
*/ | |||
private static boolean containsDefaultSwitch(DetailAST caseGroupAst) { |
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.
Changed the name of this method to be consistent with language from the JLS: https://docs.oracle.com/javase/specs/jls/se17/preview/specs/patterns-switch-jls.html
This language is also used throughout the check for consistency.
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MissingSwitchDefaultCheck.java
Outdated
Show resolved
Hide resolved
void m2(String s) { | ||
switch (s) { // ok | ||
case "a": throw new AssertionError("Wrong branch."); | ||
case default: break; |
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.
default
case label
Github, generate report |
21925fb
to
d7e667e
Compare
...uppycrawl/tools/checkstyle/checks/coding/missingswitchdefault/InputMissingSwitchDefault.java
Show resolved
Hide resolved
GitHub, rebase |
b89b1d1
to
f91ef50
Compare
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.
Item:
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MissingSwitchDefaultCheck.java
Outdated
Show resolved
Hide resolved
81fdc35
to
314603a
Compare
Github, generate site |
314603a
to
8d658f0
Compare
Github, generate site |
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.
item:
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MissingSwitchDefaultCheck.java
Outdated
Show resolved
Hide resolved
39983b1
to
d50c431
Compare
GitHub, generate web site |
Github, rebase |
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.
Ok to merge
d50c431
to
260d82b
Compare
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MissingSwitchDefaultCheck.java
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MissingSwitchDefaultCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MissingSwitchDefaultCheck.java
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MissingSwitchDefaultCheck.java
Show resolved
Hide resolved
@@ -17,7 +17,9 @@ | |||
introduction of new types in an enumeration type. Note that | |||
the compiler requires switch expressions to be exhaustive, | |||
so this check does not enforce default branches on | |||
such expressions. | |||
such expressions. Also, switch statements that use pattern or null |
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.
@romani Am I missing something that this file looks manually changed and isn't using the description in the javadoc and xdoc?
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.
@nmancus1 Are you manually modifying this file?
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.
Are you manually modifying this file?
No.
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.
Such files are updated by test that generate meta data
…attern in switch label
260d82b
to
2e8759e
Compare
GitHub, generate web site |
Closes #11220
Report label: all projects
Diff Regression config: https://gist.githubusercontent.com/nmancus1/3db3e23a5063857160d7d92cbdfa1bfe/raw/b8fc9b284c6604bf0862f237f030794bfb0a7800/config.xml
Diff Regression projects: https://raw.githubusercontent.com/checkstyle/contribution/e34312d61da0b073f31339cfbf385f289b721fed/checkstyle-tester/projects-to-test-on-for-github-action.properties
Final report: https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/f5590ec_2022232703/reports/diff/index.html
Only diffs are in openjdk17, in noncompilable files. I am not sure if we should add files filters for these files, though, since they are how I confirmed logic of check update. I think that they might be valuable in the future for similar reasons.
Blocked until #11100
Only last commit is under review.
Example of compile error on new enum value: