Core: Migrate switch statements to switch expressions#16881
Conversation
Co-authored-by: Maximilian Michels <mxm@apache.org> Co-authored-by: Manu Zhang <OwenZhang1990@gmail.com>
|
I think its a good idea to add tested locally and found more places where we should refactor |
Makes sense. Did you find it in core or other modules? I kept this scoped to core for now. Adding that would scope to other modules. Happy to do a follow up if that works better. |
steveloughran
left a comment
There was a problem hiding this comment.
commented. The new layout really makes a difference on assigment/return statements; elsewhere it can be a bit more verbose, but eliminates the risk of accident fall-throughs.
just think how many accidental fall-through bugs have been written since K & R decided that switch statements in C would fall through by default. And how many are still out there, in code we all depend on?
|
this should be good to go once the remaining comments have been addressed |
nastra
left a comment
There was a problem hiding this comment.
LGTM. Are you planning to open PR(s) to address other modules and to enable '-Xep:StatementSwitchToExpressionSwitch:ERROR'?
|
@nastra thanks for the review. Yes, I'll open follow up PRs for that and the instance of changes. |
|
From the discussion in the community sync up, any similar changes going forward should be in individual PRs and would be reviewer's discretion to allow those in. |
Co-authored-by: Maximilian Michels <mxm@apache.org> Co-authored-by: Manu Zhang <OwenZhang1990@gmail.com>
…#16881)" (apache#16953) This reverts commit 534c3fd.
Continues #15494 (@mxm) and #15176 (@manuzhang)
Summary
Converts statement-form
switchblocks iniceberg-coreto expression-form (arrow syntax). EliminatesStatementSwitchToExpressionSwitchErrorProne warnings and removes the risk of accidental fall-through in the converted code.Rationale for the change
Per the [DISCUSS] Switching to new switches dev list thread, consensus was option 2
(merge sweeping syntax changes shortly before the release). Targeting 1.12.
Changes
iceberg-coreonly. Pattern-matching forinstanceof- I'll create a separate follow-up PR.-XepPatchChecks:StatementSwitchToExpressionSwitch -XepPatchLocation:IN_PLACE), thenspotlessApply, plus a small manual cleanup inPrimitiveWrapper.sizeInBytes()to keep trailing comments inline.SingleValueParser.fromJsonwas annotated@SuppressWarnings("MethodLength")because the arrow-form blocks push it past the 150-line checkstyle limit. Should be refactored later but out of scope for a mechanical syntax migration.Test