Skip to content

Core: Migrate switch statements to switch expressions#16881

Merged
nastra merged 5 commits into
apache:mainfrom
nssalian:core-switch-expressions
Jun 24, 2026
Merged

Core: Migrate switch statements to switch expressions#16881
nastra merged 5 commits into
apache:mainfrom
nssalian:core-switch-expressions

Conversation

@nssalian

@nssalian nssalian commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Continues #15494 (@mxm) and #15176 (@manuzhang)

Summary

Converts statement-form switch blocks in iceberg-core to expression-form (arrow syntax). Eliminates StatementSwitchToExpressionSwitch ErrorProne 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-core only. Pattern-matching for instanceof - I'll create a separate follow-up PR.
  • The diff was generated by ErrorProne's auto-patcher (-XepPatchChecks:StatementSwitchToExpressionSwitch -XepPatchLocation:IN_PLACE), then spotlessApply, plus a small manual cleanup in PrimitiveWrapper.sizeInBytes() to keep trailing comments inline.
  • SingleValueParser.fromJson was 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

  • locally ran the core tests

Co-authored-by: Maximilian Michels <mxm@apache.org>
Co-authored-by: Manu Zhang <OwenZhang1990@gmail.com>
@github-actions github-actions Bot added the core label Jun 19, 2026
@nssalian nssalian added this to the Iceberg 1.12.0 milestone Jun 19, 2026
@nssalian nssalian requested review from kevinjqliu and nastra June 19, 2026 21:20
@nssalian nssalian marked this pull request as ready for review June 19, 2026 21:20
@kevinjqliu

Copy link
Copy Markdown
Contributor

I think its a good idea to add '-Xep:StatementSwitchToExpressionSwitch:ERROR', to baseline.gradle so that we can enforce this going forward and verify that all refactors are caught.

tested locally and found more places where we should refactor

@nssalian

nssalian commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

I think its a good idea to add '-Xep:StatementSwitchToExpressionSwitch:ERROR', to baseline.gradle so that we can enforce this going forward and verify that all refactors are caught.

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.

Comment thread core/src/main/java/org/apache/iceberg/avro/Avro.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/BaseFile.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/V1Metadata.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/V1Metadata.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/V2Metadata.java Outdated

@steveloughran steveloughran left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread core/src/main/java/org/apache/iceberg/puffin/PuffinFormat.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/puffin/PuffinReader.java
Comment thread core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java
@nssalian nssalian requested review from nastra and steveloughran June 23, 2026 00:33
Comment thread core/src/main/java/org/apache/iceberg/avro/GenericAvroReader.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/avro/InternalReader.java
Comment thread core/src/main/java/org/apache/iceberg/puffin/PuffinFormat.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/puffin/PuffinFormat.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/variants/PrimitiveWrapper.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/variants/VariantVisitor.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/SingleValueParser.java Outdated
@nastra

nastra commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

this should be good to go once the remaining comments have been addressed

Comment thread core/src/main/java/org/apache/iceberg/ScanTaskParser.java
@nssalian nssalian requested a review from nastra June 24, 2026 03:49

@nastra nastra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Are you planning to open PR(s) to address other modules and to enable '-Xep:StatementSwitchToExpressionSwitch:ERROR'?

@nastra nastra merged commit 534c3fd into apache:main Jun 24, 2026
54 checks passed
@nssalian

Copy link
Copy Markdown
Collaborator Author

@nastra thanks for the review. Yes, I'll open follow up PRs for that and the instance of changes.

@nssalian nssalian deleted the core-switch-expressions branch June 24, 2026 16:05
@nssalian

Copy link
Copy Markdown
Collaborator Author

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.

rdblue pushed a commit that referenced this pull request Jun 24, 2026
@nssalian nssalian removed this from the Iceberg 1.12.0 milestone Jun 24, 2026
jakelong95 pushed a commit to jakelong95/iceberg that referenced this pull request Jun 29, 2026
Co-authored-by: Maximilian Michels <mxm@apache.org>
Co-authored-by: Manu Zhang <OwenZhang1990@gmail.com>
jakelong95 pushed a commit to jakelong95/iceberg that referenced this pull request Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants