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

In Java 24 and above any rewrite-java module will fail with ClassNoDefFoundError: Type.UnknownType #4768

Open
Col-E opened this issue Dec 11, 2024 · 1 comment
Labels
bug Something isn't working java 21+ parser-java

Comments

@Col-E
Copy link

Col-E commented Dec 11, 2024

In JDK 24 per this commit in October (Respective PR) the Type.UnknownType has been removed, and its usage has been swapped out with Type.ErrorType.

Example stacktrace:

java.lang.NoClassDefFoundError: com/sun/tools/javac/code/Type$UnknownType
  org.openrewrite.java.isolated.ReloadableJava21TypeMapping.type(ReloadableJava21TypeMapping.java:49)
  org.openrewrite.java.isolated.ReloadableJava21TypeMapping.type(ReloadableJava21TypeMapping.java:387)
  org.openrewrite.java.isolated.ReloadableJava21TypeMapping.type(ReloadableJava21TypeMapping.java:380)
  org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitMemberSelect(ReloadableJava21ParserVisitor.java:894)
  org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitMemberSelect(ReloadableJava21ParserVisitor.java:75)
  com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2585)
  com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
@timtebeek
Copy link
Contributor

Thanks for referencing those external sources @Col-E ! Really helpful to gauge the adjustments we'll have to make here.

It looks like there's two classes in our Java 21 parser that use that Type.UnknownType; here's the first usages for each file:

private String signature(@Nullable Type type) {
if (type == null || type instanceof Type.UnknownType || type instanceof NullType) {
return "{undefined}";

public JavaType type(com.sun.tools.javac.code.@Nullable Type type) {
if (type == null || type instanceof Type.ErrorType || type instanceof Type.PackageType || type instanceof Type.UnknownType ||
type instanceof NullType) {
return JavaType.Class.Unknown.getInstance();
}

I'm not yet sure if this is merely the first, or the only adjustment we'll have to make. If it's the only change then we can look to do something similar as we did for Java 23, to support that using our existing Java 21 parser.

If we expect more changes, then it might make sense to fork the Java 21 parser and start a Java 24 parser without these removed type references. The best time to fork the Java 21 parser is likely after we add Lombok & JEP-440 & JEP-441 support there. Getting the timing right ensures there's less work to maintain those forks in parallel as we build out their capabilities. Lombok support is already in our Java 17 parser; these PRs track further additions to our parsers

There's some additional context also in openrewrite/rewrite-templating#118.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working java 21+ parser-java
Projects
Status: Backlog
Development

No branches or pull requests

2 participants