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

OpenRewrite fails to parse java files when using Java 23 #4513

Closed
talios opened this issue Sep 21, 2024 · 5 comments · Fixed by #4516
Closed

OpenRewrite fails to parse java files when using Java 23 #4513

talios opened this issue Sep 21, 2024 · 5 comments · Fixed by #4516
Assignees
Labels
bug Something isn't working parser-java

Comments

@talios
Copy link

talios commented Sep 21, 2024

When setting <release>23</release> on my Maven project, OpenRewrite fails to parse Javadoc, most likely due to the updates to support Markdown Javadoc.

What version of OpenRewrite are you using?

I am using the following versions:

locked org.openrewrite.maven:rewrite-maven-plugin:5.40.2;
locked org.openrewrite.recipe:rewrite-cucumber-jvm:1.5.7;
locked org.openrewrite.recipe:rewrite-java-dependencies:1.18.1;
locked org.openrewrite.recipe:rewrite-java-security:2.12.0;
locked org.openrewrite.recipe:rewrite-logging-frameworks:2.13.0;
locked org.openrewrite.recipe:rewrite-migrate-java:2.25.1;
locked org.openrewrite.recipe:rewrite-static-analysis:1.16.0;
locked org.openrewrite.recipe:rewrite-testing-frameworks:2.18.0;
locked org.openrewrite:rewrite-java:7.40.8;

How are you running OpenRewrite?

mvn clean install org.openrewrite.maven:rewrite-maven-plugin:runNoFork

What did you see instead?

[WARNING] There were problems parsing Foo.java
[WARNING] java.lang.NoSuchMethodError: 'com.sun.tools.javac.tree.DCTree$DCDocComment com.sun.tools.javac.tree.DocCommentTable.getCommentTree(com.sun.tools.javac.tree.JCTree)'
  org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.convert(ReloadableJava21ParserVisitor.java:1666)
  org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitCompilationUnit(ReloadableJava21ParserVisitor.java:537)
  org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitCompilationUnit(ReloadableJava21ParserVisitor.java:73)
  com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:625)
  com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
@timtebeek
Copy link
Contributor

Thanks for the report @talios ! Good to track this here. I'd already explored this briefly after getting a report through

In short we're having to depend on an internal API, which seems to have changed.

private <J2 extends J> J2 convert(Tree t) {
try {
String prefix = source.substring(cursor, max(((JCTree) t).getStartPosition(), cursor));
cursor += prefix.length();
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, docCommentTable.getCommentTree((JCTree) t)));

Java 21: DCDocComment getCommentTree(JCTree tree)
Java 23: DocCommentTree getCommentTree(JCTree tree);

@timtebeek
Copy link
Contributor

Here's a PR that aims to fix this:

@timtebeek timtebeek moved this to Ready to Review in OpenRewrite Sep 23, 2024
@timtebeek timtebeek self-assigned this Sep 23, 2024
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Sep 23, 2024
@triceo
Copy link

triceo commented Sep 29, 2024

FYI @timtebeek The issue doesn't go away after upgrading to 8.36.0.

@timtebeek
Copy link
Contributor

Are you seeing the exact same error? Since that line was changed..

@triceo
Copy link

triceo commented Sep 29, 2024

Hmm, no, I'm seeing a different one, sorry:

Caused by: org.openrewrite.java.JavaParsingException: Failed to convert for the following cursor stack:--- BEGIN PATH ---
at org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1669)

I'll file a new issue for that.

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

Successfully merging a pull request may close this issue.

3 participants