Fix ChangeType UnsupportedOperationException on JS FunctionCall nodes#7239
Merged
knutwannheden merged 3 commits intomainfrom Apr 2, 2026
Merged
Conversation
b5f46c2 to
b7a680a
Compare
timtebeek
approved these changes
Apr 2, 2026
ChangeType.postVisit() falls through to the TypedTree branch for JS.FunctionCall nodes, which throws UnsupportedOperationException because withType() is not supported on MethodCall implementations. Add a MethodCall catch-all branch before the TypedTree fallback that uses withMethodType() instead, handling JS.FunctionCall and any other future MethodCall implementations not explicitly handled.
b7a680a to
0bceb5c
Compare
This test exercises the JS RPC parser and belongs with the other integration tests that are not run in CI.
ChangeType UnsupportedOperationException on JS FunctionCall nodes
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.
Motivation
When running Java recipes (e.g.,
NoGuavaPredicate→ChangeType) against repositories containing JavaScript files,ChangeType.postVisit()throwsUnsupportedOperationExceptiononJS.FunctionCallnodes. This was discovered in flagship recipe run alerts on app.moderne.io — the "Java best practices" recipe run against Netflix+Spring org produced 46 per-file errors onmetaflow/plugins/cards/ui/prism.js.The root cause:
ChangeType.postVisit()has explicit handling forJ.MethodInvocationandJ.NewClass(bothMethodCallimplementations), butJS.FunctionCall— also aMethodCall— falls through to the genericTypedTreebranch, which callswithType(). AllMethodCallimplementations throwUnsupportedOperationExceptiononwithType()because the type is derived from the method type.Additionally,
J.ClassDeclaration.type(aJavaType.FullyQualified) was not being serialized over RPC, causing JavaScript class declarations to lose their type attribution when crossing the RPC boundary.Summary
MethodCallcatch-all branch inChangeType.postVisit()between theJ.NewClassandTypedTreebranches, usingwithMethodType()instead ofwithType()J.ClassDeclaration.typeto the RPC sender/receiver in all language implementations (Java, TypeScript, C#, Python)ChangeTypeAdaptabilityTestinrewrite-javascriptthat verifiesChangeTypecan handle JS source containingFunctionCallnodesTest plan
ChangeTypeAdaptabilityTest.functionCallDoesNotThrow()— appliesChangeType("Foo", "Bar", false)to JavaScript containing a class with a method returning a function, verifying both the class rename and thatJS.FunctionCallnodes don't cause exceptionsChangeTypeTestinrewrite-java-testpassesChangeTypeAdaptabilityTestinrewrite-groovypassesChangeTypeTestinrewrite-kotlinpasses