Skip to content

Complete Java 24 compatibility fix by backporting UnknownType workaround#6740

Merged
timtebeek merged 1 commit intoopenrewrite:mainfrom
kdvolder:fix/java24-unknown-type-backport
Feb 14, 2026
Merged

Complete Java 24 compatibility fix by backporting UnknownType workaround#6740
timtebeek merged 1 commit intoopenrewrite:mainfrom
kdvolder:fix/java24-unknown-type-backport

Conversation

@kdvolder
Copy link
Copy Markdown
Contributor

@kdvolder kdvolder commented Feb 13, 2026

Background:

  • April 2025: JDK 24 support added with reflection-based workarounds
  • May 2025: Workarounds removed in "simplification" (commit 08b08ab)
  • February 2026: DocCommentTable fix backported in PR Support Gradle 8.x on Java 23+ #6725
  • This PR: Backports the missing UnknownType fix

Problem:
Java 24 removed the Type.UnknownType class from javac internals. Direct instanceof Type.UnknownType checks cause NoClassDefFoundError at runtime on Java 24.

Solution:
Use reflection to check the class name at runtime instead of compile-time instanceof checks. This allows the code to work on both Java 21-23 (where the class exists) and Java 24+ (where it doesn't).

Changes:

  • ReloadableJava21TypeMapping.java: Added isUnknownType() helper, replaced 3 instanceof checks
  • ReloadableJava21TypeSignatureBuilder.java: Replaced 2 instanceof checks

Testing:
Verified on spring-petclinic project with Java 24.0.2. Type attribution works correctly, ChangeType and ChangePackage recipes execute successfully, and migrated code compiles without errors.

This completes the Java 24 compatibility work started in PR openrewrite#6725 by
backporting the isUnknownType() helper method that was removed during
the May 2025 simplification (commit 08b08ab).

Background:
- April 2025: JDK 24 support added with reflection-based workarounds
- May 2025: Workarounds removed in "simplification" (commit 08b08ab)
- February 2026: DocCommentTable fix backported in PR openrewrite#6725
- This PR: Backports the missing UnknownType fix

Problem:
Java 24 removed the Type.UnknownType class from javac internals.
Direct instanceof Type.UnknownType checks cause NoClassDefFoundError
at runtime on Java 24.

Solution:
Use reflection to check the class name at runtime instead of compile-time
instanceof checks. This allows the code to work on both Java 21-23 (where
the class exists) and Java 24+ (where it doesn't).

Changes:
- ReloadableJava21TypeMapping.java: Added isUnknownType() helper, replaced
  3 instanceof checks
- ReloadableJava21TypeSignatureBuilder.java: Replaced 2 instanceof checks

Testing:
Verified on spring-petclinic project with Java 24.0.2. Type attribution
works correctly, ChangeType and ChangePackage recipes execute successfully,
and migrated code compiles without errors.

Fixes: openrewrite#6644
Related: openrewrite#6725, commit 08b08ab
Copy link
Copy Markdown
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the helpful links back to older commits that had introduced the same. Hope this is the final bit we need to restore Gradle 8.x on newer Java versions.

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Feb 14, 2026
@timtebeek timtebeek merged commit 3fbb6ea into openrewrite:main Feb 14, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Java25Parser compiled with Java 25 breaks Java 24 runtime compatibility

2 participants