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

JDK 16: final variable in pattern matching with instanceof #588

Closed
agavrilov76 opened this issue Apr 11, 2021 · 1 comment · Fixed by #592
Closed

JDK 16: final variable in pattern matching with instanceof #588

agavrilov76 opened this issue Apr 11, 2021 · 1 comment · Fixed by #592
Assignees

Comments

@agavrilov76
Copy link

Declaring a variable final when matching pattern with instanceof operator causing an exception.

Code example:

if (person instanceof final Customer customer) {
    customer.pay();
}

Error:

com.google.googlejavaformat.java.FormatterException: 83:33: error: did not generate token "final"
    at com.google.googlejavaformat.java.Formatter.getFormatReplacements (Formatter.java:293)
    at com.google.googlejavaformat.java.Formatter.formatSource (Formatter.java:267)
    at com.google.googlejavaformat.java.Formatter.formatSource (Formatter.java:233)
    at com.coveo.AbstractFMT.formatSourceFile (AbstractFMT.java:216)
    at com.coveo.AbstractFMT.lambda$formatSourceFilesInDirectory$1 (AbstractFMT.java:157)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:197)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:179)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:179)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:197)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:179)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1625)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:484)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.ReduceOps$ReduceTask.doLeaf (ReduceOps.java:952)
    at java.util.stream.ReduceOps$ReduceTask.doLeaf (ReduceOps.java:926)
    at java.util.stream.AbstractTask.compute (AbstractTask.java:327)
    at java.util.concurrent.CountedCompleter.exec (CountedCompleter.java:746)
    at java.util.concurrent.ForkJoinTask.doExec (ForkJoinTask.java:295)
    at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec (ForkJoinPool.java:1016)
    at java.util.concurrent.ForkJoinPool.scan (ForkJoinPool.java:1665)
    at java.util.concurrent.ForkJoinPool.runWorker (ForkJoinPool.java:1598)
    at java.util.concurrent.ForkJoinWorkerThread.run (ForkJoinWorkerThread.java:183)
@cushon
Copy link
Collaborator

cushon commented Apr 11, 2021

Thanks for the report, it looks like this wasn't supported prior to JDK 16: https://bugs.openjdk.java.net/browse/JDK-8257759

@cushon cushon self-assigned this Apr 11, 2021
copybara-service bot pushed a commit that referenced this issue Apr 12, 2021
Fixes #588

PiperOrigin-RevId: 367902205
copybara-service bot pushed a commit that referenced this issue Apr 12, 2021
Fixes #588

PiperOrigin-RevId: 367902205
copybara-service bot pushed a commit that referenced this issue Apr 13, 2021
Fixes #588

PiperOrigin-RevId: 367902205
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Dec 13, 2021
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 7, 2022
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 7, 2022
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 7, 2022
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 10, 2022
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

Successfully merging a pull request may close this issue.

2 participants