palantir / palantir/palantir-java-format
FormatterException on combined `null, default` switch expression branch
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 907
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
Hi team, case null, default -> is a common pattern in switch expressions (explicit null is required for compatibility with older switch statements). But it crashes the formatter, e.g. the code below results in /YourFile.java: com.palantir.javaformat.java.FormatterException: 48:13: error: expected token: 'default'; generated - instead -> [Help 1]
public void onReceive(Object message) {
switch (message) {
//...
case null, default -> super.unhandled(message);
}
}
Splitting the case into two separated cases with identical bodies helps, but it's obviously a subpar workaround because it causes static analyzer warnings + prevents switching to palantir-java-formatter without migrating all affected switches in the codebase first.
Thanks !
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the formatter failure with the provided Java switch-expression example and trace how combined null, default case labels are parsed. Done means the formatter accepts this syntax without raising FormatterException and preserves the intended switch expression formatting; add or update a regression test where the project's existing formatter tests cover this behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100