google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

Native version fails to format record patterns in switches if the first nested pattern is final

Open Ontonator opened this issue 6 months ago • 1 comments

The following code fails to format when using the native version of the formatter. (The JVM version works fine.)

class Main {
    void test() {
        switch (test) {
            case Test(final var x, final var y) -> {}
        }
    }
}

On the other hand, both of these examples are accepted:

class Main {
    void test() {
        switch (test) {
            case Test(var x, final var y) -> {}
        }
    }
}
class Main {
    void test() {
        if (test instanceof Test(final var x, final var y)) {}
    }
}

Tested on version 1.27.0.

Ontonator avatar Jun 04 '25 13:06 Ontonator

This might be resolved by updating the GraalVM version for releases, I think we could switch to 25 now:

https://github.com/google/google-java-format/blob/60a00f20dd6a2f754774617aa803d06ad26a5ac4/.github/workflows/release.yml#L105

cushon avatar Oct 28 '25 19:10 cushon