Skip to content

Core: Fix all ErrorProne warnings after Java 17 upgrade - #15494

Closed
mxm wants to merge 1 commit into
apache:mainfrom
mxm:fix-warnings-core
Closed

mxm wants to merge 1 commit into
apache:mainfrom
mxm:fix-warnings-core

Conversation

@mxm

@mxm mxm commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

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 forgetting break statements in switch statements, switch expressions are exhaustive by default.

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.
@github-actions github-actions Bot added the core label Mar 2, 2026
@pvary

pvary commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

@manuzhang posted a PR about changing the switch statements. See: #15176
The general consensus was that we push these sweeping changes to just before the release, so companies who maintain their internal Iceberg versions will have an easier time.

@manuzhang

Copy link
Copy Markdown
Member

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?

@mxm

mxm commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @pvary! I hadn't seen @manuzhang's PR, despite searching for similar PRs before opening this one. I'll close this one then.

@manuzhang

manuzhang commented Mar 2, 2026 •

Copy link
Copy Markdown
Member

@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.

@pvary

pvary commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

@manuzhang: Yeah, bump the thread the release is coming 😄

@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.

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 -> {

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.

so even for those one-liners the style is going to be mandatory { } blocks? it does make the switches a lot more verbose.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@steveloughran We can get rid of {} blocks as in my version, #15176, which is less verbose.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@mxm

mxm commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

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 yield is when you're assigning a variable in a case. That should be replaced by a yield. As for return statement, I'm not 100% sure. One thing to consider is that we don't enforce yielding in methods today, i.e. return statement can be used freely anywhere in the the method.

Interesting followup here: would legacy switch() be something checkstyle would block? Given the fallthrough risks of the legacy statement, it does make sense.

Yes, there is this check to get rid of the legacy switch: https://checkstyle.sourceforge.io/checks/coding/useenhancedswitch.html

Did you find any switches where the fall-through behaviour was actually required?

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
}

@steveloughran

Copy link
Copy Markdown
Contributor

@mxm thank's for the analysis and insight.
I just checked the hadoop codebase for the comment "fall through" with any form of computation between the cases. The JenkinsHash hash algorithm is the only place where something has taken serious advantage of fall through; the remaining 20 uses are fairly minimal. The only one which is my fault is error handling and highlights that code is due for a cleanup.

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".

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label Apr 9, 2026
@steveloughran

Copy link
Copy Markdown
Contributor

not stale, we need this to keep builds quieter, and it needs to go in before more merge conflict surfaces

@github-actions github-actions Bot removed the stale label Apr 10, 2026
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label May 10, 2026
@steveloughran

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot removed the stale label May 12, 2026
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label Jun 11, 2026
@github-actions

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants