Conversation
Kotlin sources resolve the CommentService through K.CompilationUnit.service(), which falls back to JavaSourceFile.service() providing JavaCommentService since 8.86.0. These tests pin that AddCommentToMethodInvocations adds comments to Kotlin method invocations (and stays idempotent), and that the Comments trait intentionally errors out on source files whose language registers no CommentService.
timtebeek
approved these changes
Jul 3, 2026
greg-at-moderne
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
Test-only change:
rewrite-kotlin: a Kotlin counterpart toAddCommentToMethodInvocationsTestproving the recipe adds a comment to a Kotlin method invocation and stays idempotent when an equivalent line or block comment already exists.rewrite-core: aCommentstrait test pinning that a source file whose language registers noCommentServiceis a hardUnsupportedOperationException, not a silent skip, and that the trait requires a cursor rooted at aSourceFile.What's your motivation?
A customer running
org.openrewrite.java.AddCommentToMethodInvocationsagainst Kotlin sources hit:(moderneinc/customer-requests#2673)
Since Create a Comments trait to make it easy to add formatted comments to LST elements. #8131,
JavaSourceFile.service()resolvesCommentServicetoJavaCommentService, andK.CompilationUnit.service()falls back to it — so Kotlin (like Groovy) is served by the sharedJ-model implementation and the failure no longer reproduces on a coherent 8.86.0+ classpath. The crash only occurs when an olderrewrite-javais mixed with a newerrewrite-core/rewrite-kotlin. These tests pin the working behavior so it cannot regress, and document that erroring out (rather than silently skipping) is the intended contract for languages without aCommentService.Anyone you would like to review specifically?
@timtebeek