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

Fail to reformat by JDK17 for Pattern Matching for instanceof #768

Closed
bluebu opened this issue Mar 20, 2022 · 6 comments
Closed

Fail to reformat by JDK17 for Pattern Matching for instanceof #768

bluebu opened this issue Mar 20, 2022 · 6 comments

Comments

@bluebu
Copy link

bluebu commented Mar 20, 2022

https://openjdk.java.net/jeps/394

idea version: 2021.3.2 (Ultimate Edition)

plugin version: 1.15.0.0

JDK version: Amazon corretto 17.0.2

the reformat doesn't work, if has the code below:

if (a instanceof String str) {
   System.out.println(str)
}

the reformat will work, if I delete any code with "Pattern Matching for instanceof" operator

@MatthewRyanRead
Copy link

MatthewRyanRead commented Jun 10, 2022

Reproduced in 2022.1.2 with plugin 1.15.0.0 (formatter 1.15.0) on Temurin-17.0.2+8.

https://github.com/spotify/fmt-maven-plugin and https://github.com/diffplug/spotless both appear to handle this construction perfectly, so it seems specific to the IntelliJ plugin rather than to the library generally.

@tbroyer
Copy link
Contributor

tbroyer commented Jun 10, 2022

Is this when running IDEA itself with JDK 17 ? or only using JDK 17 as the "project JDK" ?

See #533

@MatthewRyanRead
Copy link

I was using 17 as the project JDK while using the default 11 runtime for the IDE.

However, I can also reproduce this on the 2022.2 EAP version of IntelliJ, which runs on their bundled 17.0.3+7-469.3-jcef runtime at the moment.

@zxeoc
Copy link

zxeoc commented Jul 27, 2022

In my case, it works fine with project JDK 17 & JBR 11. It fails after I update IDEA to 2022.2, which switches to JBR 17 by default.

@tbroyer
Copy link
Contributor

tbroyer commented Jul 27, 2022

IIRC, #533 is about using the appropriate JDK (JBR) for running the IDE (corresponding to your project JDK, i.e. you can't use JBR 11 to format Java 17 code), and #787 when using 2022.2.

@cushon
Copy link
Collaborator

cushon commented Aug 4, 2022

I think this is covered by the issues @tbroyer mentioned. The formatter itself can handle these constructs, but only when running on a JVM that supports them:

java -jar google-java-format-1.15.0-all-deps.jar T.java
class T {
  {
    if (a instanceof String str) {
      System.out.println(str);
    }
  }
}

@cushon cushon closed this as completed Aug 4, 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

No branches or pull requests

5 participants