You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#4534 was closed under the assumption that the reporter's problem was their project was picking up the Java 17 parser and not the patched Java 21 parser (with #4516))
Unfortunately, even with the provided patched rewrite-java-21 parsing code on Java 23 fails with an exception:
Compiling against 22 or below makes method reference with a return type DCDocComment which cannot be coerced to be the looser DocCommentTree that would be compatible on newer JDK's
Solutions
Create a rewrite-java-23 module
Compile rewrite-java-21 against JDK 23 but with a target version of Java 21
This should emit a method reference to the method with a looser return type, and since the older Java code's return value implements the interface type of the new methods return type it should be compatible
Assuming the rewrite-java-21 is thoroughly covered, any other possible changes from targeting the newer API (with a compatible bytecode output though) that are incompatible should be caught by the tests
Use reflection to support use from both <23 and >=23
Reflection solution:
// Lookup by name does not require strict contract with return typeMethodgetCommentTreeMethod = DocCommentTable.class.getMethod("getCommentTree", JCTree.class);
// DCTree.DCDocComment implements DocCommentTree so the cast is safe in both 22- and 23+DocCommentTreevalue = (DocCommentTree) getCommentTreeMethod.invoke(table, (Object) null);
Workarounds
Run your application on Java 22 or lower
The text was updated successfully, but these errors were encountered:
Thanks a lot for pulling together all the relevant context here @Col-E , and outlining possible next steps. I'll pass this along to colleagues as I'm traveling, but if you want to push up the reflection fix that ought to be manageable to review on the go. I don't see us adding a Java 23 specific parser for now, as it's quite a bit to maintain for a non-LTS version.
Overview
#4534 was closed under the assumption that the reporter's problem was their project was picking up the Java 17 parser and not the patched Java 21 parser (with #4516))
Unfortunately, even with the provided patched
rewrite-java-21
parsing code on Java 23 fails with an exception:The problem
The line in question is here:
ReloadableJava21ParserVisitor.java#L1667
rewrite-java-21
module is sensibly compiled against JDK 21DocCommentTable.getCommentTree
is expecting the return type to be what was defined in the JDK 21 coderewrite-java-21
on JDK 23 crashes because thegetCommentTree
changed the return type in a non-binary compatible wayDocCommentTable.java#L69
- return type iscom.sun.tools.javac.tree.DCTree.DCDocComment
DocCommentTable.java#L69
- return type iscom.sun.source.doctree.DocCommentTree
DCDocComment
which cannot be coerced to be the looserDocCommentTree
that would be compatible on newer JDK'sSolutions
rewrite-java-23
modulerewrite-java-21
against JDK 23 but with a target version of Java 21rewrite-java-21
is thoroughly covered, any other possible changes from targeting the newer API (with a compatible bytecode output though) that are incompatible should be caught by the testsReflection solution:
Workarounds
The text was updated successfully, but these errors were encountered: