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

google-java-format Idea plugin does not work on jdk21 version.Please provide support if possible. #1100

Open
LiJun990105 opened this issue May 14, 2024 · 1 comment
Labels

Comments

@LiJun990105
Copy link

image image
@cushon
Copy link
Collaborator

cushon commented May 24, 2024

The formatter has support for those features:

$ java -jar google-java-format-1.22.0-all-deps.jar T.java
package com.google.errorprone.bugpatterns;

class T {
  private static <V> void add(JsonNode jsonNode, String key, V value) {
    switch (value) {
      case String s -> ((ObjectNode) jsonNode).put(key, s);
      case Short i -> ((ObjectNode) jsonNode).put(key, i);
      case Integer i -> ((ObjectNode) jsonNode).put(key, i);
      case Long l -> ((ObjectNode) jsonNode).put(key, 1);
      case Float v -> ((ObjectNode) jsonNode).put(key, v);
      case Double v -> ((ObjectNode) jsonNode).put(key, v);
      case BigDecimal bigDecimal -> ((ObjectNode) jsonNode).put(key, bigDecimal);
      case BigInteger bigInteger -> ((ObjectNode) jsonNode).put(key, bigInteger);
      case Boolean b -> ((ObjectNode) jsonNode).put(key, b);
      case byte[] bytes -> ((ObjectNode) jsonNode).put(key, bytes);
      case null, default -> ((ObjectNode) jsonNode).put(key, to(value));
    }
  }
}

The issue is that it needs to be running on a JDK version that is new enough to recognize them, so if IntelliJ is using an older boot JDK it won't work. Configuring IntelliJ to run on JDK 22 works around the error: https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under

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

No branches or pull requests

2 participants