Skip to content

Conversation

@Laurens-W
Copy link
Contributor

What's changed?

Initial setup of Java 25 parser based on the Java 21 variant

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@Laurens-W
Copy link
Contributor Author

I think the rewrite-gradle-plugin can't handle Java 25 just yet, hence why it's spewing out so many diffs, there's a concurrency issue. I can reproduce it locally

@timtebeek
Copy link
Member

There's a bit of a hack still in the Java 21 parser, which we wouldn't need there anymore following the new matching of Java versions with LTS parsers. Can we remove that handling from the Java 21 parser?

// Java 21 and 23 have a different return type from getCommentTree; with reflection we can support both
Method getCommentTreeMethod = DocCommentTable.class.getMethod("getCommentTree", JCTree.class);
DocCommentTree commentTree = (DocCommentTree) getCommentTreeMethod.invoke(docCommentTable, t);
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, commentTree));

And I say that as the one that added it; ideally we push folks to the next LTS parser as opposed to back porting based on what folks happen to have on the classpath.

Comment on lines +981 to +985
// The AST contained unnecessary whitespace for Javadoc, and they got rid of this with Java 25.
// So now have to manually account for this.
if (i+1 <= node.length() -1 && node.charAt(i+1) != source.charAt(cursor) && Character.isWhitespace(source.charAt(cursor))) {
text.append(whitespaceBeforeAsString());
}
Copy link
Member

Choose a reason for hiding this comment

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

These lines are new as compared to the Java 21 parser; they look fine to me; figured call these out for wider review as the rest of the file is identical between 21 and 25.

@timtebeek
Copy link
Member

Similarly to above, we can revert this ward that was added to the Java 21 parser to support Java 24:

/**
* Check for the `UnknownType` which existed up until JDK 22; starting with JDK 23 only the `ErrorType` is used
*/
public static boolean isUnknownType(@Nullable Type type) {
return type != null && type.getClass().getName().equals("com.sun.tools.javac.code.Type$UnknownType");
}

We'd want to revert to the simple type instanceof Type.UnknownType check that we had before these two PRs:

github-actions[bot]

This comment was marked as duplicate.

Comment on lines 17 to 23
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@main
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@java25
with:
java_version: |
25-ea
21
recipe: 'org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPracticesSubset'
additional_gradle_args: '-Drewrite.exclusion=**/rewrite-java-25/**'
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we should temporarily disable this workflow completely, such that we can merge the Java 25 parser and aim to fix the runtime issues downstream that cause the excessive suggstions to be reported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems like the only way forward, it is gonna be a challenge though, since the rewrite-gradle-plugin doesn't seem immediately fit for Gradle 9, but I can continue looking into that one :)

@timtebeek
Copy link
Member

Now seeing the same suspicious code suggestions in an unrelated PR, so perhaps we don't have to trouble shoot that here:

@Laurens-W
Copy link
Contributor Author

Now seeing the same suspicious code suggestions in an unrelated PR, so perhaps we don't have to trouble shoot that here:

I was explicitly able to reproduce by changing my system jdk to 25 explicitly and running the plugin as we do in the pipeline though

@timtebeek timtebeek marked this pull request as ready for review September 1, 2025 12:14
Copy link
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.

Great to see, thanks for taking the time to remove some oddities from our older parsers, ensure going forward we pick the right next parser, and can now move on to making the other parts work for Java 25+.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Sep 1, 2025
@Laurens-W Laurens-W merged commit ca7b9b7 into main Sep 1, 2025
2 checks passed
@Laurens-W Laurens-W deleted the java25-parser branch September 1, 2025 13:16
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Sep 1, 2025
Laurens-W added a commit that referenced this pull request Sep 1, 2025
Laurens-W added a commit that referenced this pull request Sep 1, 2025
Laurens-W added a commit that referenced this pull request Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request java 25+ parser

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants