Skip to content

Commit ae70bc3

Browse files
kdvoldertimtebeek
andauthored
Fix Java 24 runtime compatibility by falling back to Java 21 parser (#6682)
* Fix Java 24 runtime compatibility by falling back to Java 21 parser Changes parser selection logic to only use Java25Parser on Java 25+ runtime, allowing Java 24 to fall back to Java21Parser. Background: - Java25Parser is compiled with Java 25 (class version 69) - Java 24 runtime only supports up to class version 68 - Java21Parser can successfully parse Java 23 and 24 source code This change prevents UnsupportedClassVersionError when running OpenRewrite on Java 24 runtime while maintaining full functionality. * Update branch of javaee samples to target to 'main' * Update the Java versions picked & document recommendations * Revert unrelated change --------- Co-authored-by: Tim te Beek <tim@moderne.io>
1 parent dbfd350 commit ae70bc3

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,21 +441,24 @@ class JdkParserBuilderCache {
441441

442442
// Try to find and cache appropriate parser
443443

444-
// Java 23+ changed the return type of `DocCommentTable.getCommentTree` from `DCDocComment` to `DocCommentTree`
445-
// That means Java 23 and above need the Java 25 parser, whereas Java 22 and below need the Java 21 parser
446-
if (version > 22) {
444+
// Parsers are compiled only for their matching Java version, given their use of internal/unstable APIs.
445+
// Language features introduced in non-LTS versions are only supported from the next LTS version onwards.
446+
// We recommend running on LTS versions wherever possible; non-LTS versions may struggle given the above.
447+
// e.g.: Java 23+ changed the return type of `DocCommentTable.getCommentTree` from `DCDocComment` to `DocCommentTree`
448+
449+
if (version >= 25) {
447450
supplier = tryCreateBuilderSupplier("org.openrewrite.java.Java25Parser");
448451
}
449452

450-
if (version > 17 && supplier == null) {
453+
if (supplier == null && version >= 21) {
451454
supplier = tryCreateBuilderSupplier("org.openrewrite.java.Java21Parser");
452455
}
453456

454-
if (version > 11 && supplier == null) {
457+
if (supplier == null && version >= 17) {
455458
supplier = tryCreateBuilderSupplier("org.openrewrite.java.Java17Parser");
456459
}
457460

458-
if (version > 8 && supplier == null) {
461+
if (supplier == null && version >= 11) {
459462
supplier = tryCreateBuilderSupplier("org.openrewrite.java.Java11Parser");
460463
}
461464

0 commit comments

Comments
 (0)