Skip to content

Commit c313f69

Browse files
committed
Report when the selected formatter runtime is too old for the JDK
1 parent 18caf24 commit c313f69

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

plugin/src/main/scala/com/github/sbt/javaformatter/JavaFormatter.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,20 @@ object JavaFormatter {
378378
output.contains("NoClassDefFoundError: com/sun/tools/javac/tree/JCTree$JCAnyPattern") ||
379379
output.contains("ClassNotFoundException: com.sun.tools.javac.tree.JCTree$JCAnyPattern")
380380

381+
val olderFormatterOnNewerJdk =
382+
output.contains("NoSuchMethodError") &&
383+
(output.contains("com.sun.tools.javac.") || output.contains("jdk.compiler"))
384+
381385
if (unsupportedClassVersion || missingNewerJavacClass) {
382386
Some(
383387
s"\n\n\nThe forked google-java-format JVM appears to be running on an incompatible Java version. " +
384388
s"Either set the $JavaHomeEnvVar environment variable or -D$JavaHomeProperty=... to point the formatter to a compatible JDK, " +
385389
s"or lower the sbt setting ThisBuild / javafmtFormatterCompatibleJavaVersion to match the available Java runtime.\n\n\n")
390+
} else if (olderFormatterOnNewerJdk) {
391+
Some(
392+
s"\n\n\nThe selected google-java-format runtime appears to be too old for the Java version used to launch the formatter JVM. " +
393+
s"Try increasing the sbt setting ThisBuild / javafmtFormatterCompatibleJavaVersion, " +
394+
s"or point the formatter to an older compatible JDK via the $JavaHomeEnvVar environment variable or -D$JavaHomeProperty=....\n\n\n")
386395
} else {
387396
None
388397
}

0 commit comments

Comments
 (0)