Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatterException on combined null, default switch expression branch #1096

Open
hennadii-datadog opened this issue Jun 12, 2024 · 2 comments

Comments

@hennadii-datadog
Copy link

hennadii-datadog commented Jun 12, 2024

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 !

@singron
Copy link

singron commented Jul 1, 2024

See #952

@thijmenketel
Copy link

Any progress on this? I was hoping that with the release of 2.48.0 it would be fixed... Java 21 has been out for quite a while now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants