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

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

Open sk8breeze opened this issue 1 year ago • 1 comments

image image

sk8breeze avatar May 14 '24 08:05 sk8breeze

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

cushon avatar May 24 '24 20:05 cushon