Repository navigation
Conversation
This gets rid of 257 warnings in the build of iceberg-core, all of them caused by these two ErrorProne rules: - StatementSwitchToExpressionSwitch: https://errorprone.info/bugpattern/StatementSwitchToExpressionSwitch - PatternMatchingInstanceof: https://errorprone.info/bugpattern/PatternMatchingInstanceof After these changes, there are no warnings left in iceberg-core.
|
@manuzhang posted a PR about changing the switch statements. See: #15176 |
|
Thanks @pvary for mentioning my PR. I don't think there's consensus yet on when to make the changes. Do you want to bump the thread? |
|
Thanks @pvary! I hadn't seen @manuzhang's PR, despite searching for similar PRs before opening this one. I'll close this one then. |
|
@mxm You don't need to. Maybe it's better to fix all warnings in one PR. Let's wait for consensus from the community. |
|
@manuzhang: Yeah, bump the thread the release is coming 😄 |
steveloughran
left a comment
There was a problem hiding this comment.
instanceof is wonderful and will shut the compiler up.
the switch statement are a bit inconsistent w.r.t {} clauses, unguarded operations and return vs yield.
it'd be good to have policy here, using your experience as the source of that policy.
what do you think is best? I'm thinking maybe "any case clause with side effects is in a {} clause, and prefer yield over return for its completeness and ability to say `int x = switch(y) { ... }.
unsure about the merits of not having {} wrappers around case clauses which only return data.
Interesting followup here: would legacy switch() be something checkstyle would block? Given the fallthrough risks of the legacy statement, it does make sense. Did you find any switches where the fall-through behaviour was actually required?
|
|
||
| switch (primitive.getType()) { | ||
| case NULL: | ||
| case NULL -> { |
There was a problem hiding this comment.
so even for those one-liners the style is going to be mandatory { } blocks? it does make the switches a lot more verbose.
There was a problem hiding this comment.
@steveloughran We can get rid of {} blocks as in my version, #15176, which is less verbose.
There was a problem hiding this comment.
I tried to get rid of curly brackets wherever possible. Here, we cannot remove them because we have a return statement following. The implicit return like in lambdas without curly brackets only works if we yield a value from the switch statement.
Curly brackets: I generally tried to remove the curly brackets where possible. For readability it can still make sense to use curly brackets, e.g. when there is a comment in the case block. Unguarded operations: Those aren't possible anymore with switch expressions. IMHO we shouldn't be using legacy switch statements anymore. See below for the Checkstyle rule to enforce this. return vs yield: The most obvious case for
Yes, there is this check to get rid of the legacy switch: https://checkstyle.sourceforge.io/checks/coding/useenhancedswitch.html
Yes, there are a couple of instances. They were easy to convert though. The basic pattern is: switch (myEnum) {
case A:
case B:
// do something
break;
case C:
// do something else
}becomes switch (myEnum) {
case A, B ->
// do something
case C ->
// do something else
}edit: I just realized, there can also be a case like this which isn't that straight-forward: switch (myEnum) {
case A:
// do something A
case B:
// do something B
break;
case C:
// do something else
}which would be: switch (myEnum) {
case A -> {
// do something A
// do something B
}
case B ->
// do something B
case C ->
// do something else
} |
|
@mxm thank's for the analysis and insight. It really highlights how the classic C design solved a problem which doesn't exist in high level code while adding a new problem "unintentional fall through". |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
|
not stale, we need this to keep builds quieter, and it needs to go in before more merge conflict surfaces |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
|
this should be rebased and kept alive...during builds we get told off by javac for all of this stuff, and this is the fix |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
|
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
This gets rid of 257 warnings in the build of iceberg-core, all of them caused by these two ErrorProne rules:
After these changes, there are no warnings left in iceberg-core.
Overall, these changes make the code more readable and less error-prone, e.g. no more casts after
instanceof, no more forgettingbreakstatements in switch statements, switch expressions are exhaustive by default.