Fix ChangeType UOE on JS.ComputedPropertyMethodDeclaration#7418
Draft
knutwannheden wants to merge 1 commit intomainfrom
Draft
Fix ChangeType UOE on JS.ComputedPropertyMethodDeclaration#7418knutwannheden wants to merge 1 commit intomainfrom
ChangeType UOE on JS.ComputedPropertyMethodDeclaration#7418knutwannheden wants to merge 1 commit intomainfrom
Conversation
`ChangeType.postVisit` walks `TypedTree` and calls `withType(..)`. For method-declaration-shaped nodes that redirect the return type through `withMethodType(..)`, `withType(..)` throws `UnsupportedOperationException`. `J.MethodDeclaration` had a dedicated branch, but `JS.ComputedPropertyMethodDeclaration` (`JS, Statement, TypedTree`) fell through to the generic `TypedTree` branch and crashed. Introduce `MethodDeclarationLike` (parallel to `MethodCall`) implemented by `J.MethodDeclaration` and `JS.ComputedPropertyMethodDeclaration`, and add a catch-all branch in `ChangeType.postVisit` before the `TypedTree` fallback.
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
ChangeType.postVisitcrashes withUnsupportedOperationExceptionwhen it encountersJS.ComputedPropertyMethodDeclaration:This is the third variant of the same underlying issue:
ChangeTypeUnsupportedOperationExceptionon JSFunctionCallnodes #7239 added aMethodCallcatch-all forJS.FunctionCalletc.Py.ExpressionTypeTree.withType()itself.JS.ComputedPropertyMethodDeclaration, which implementsJS, Statement, TypedTree(notMethodCall, notJ.MethodDeclaration), so it hit the genericTypedTreefallback.Observed volume: ~13 per-file errors/day on production runs of
NoGuavaPredicate(a sub-recipe of "Java best practices") against TypeScript repositories.Summary
org.openrewrite.java.tree.MethodDeclarationLike(parallel toMethodCall) exposesgetMethodType()/withMethodType(..).J.MethodDeclarationandJS.ComputedPropertyMethodDeclarationnow implement it (signatures were already there).ChangeType.postVisithas a new branch forMethodDeclarationLike, placed after theMethodCallbranch and before the genericTypedTreefallback.ChangeTypeAdaptabilityTest#computedPropertyMethodDeclarationDoesNotThrowexercises the path end-to-end.Known follow-up
K.SpreadArgumentandK.StatementExpressionalso throw UOE fromwithType(..), but their semantics ("cannot be changed directly" / "cannot have a type") do not fitMethodDeclarationLike. Those are not addressed here and would need separate handling.Test plan
ChangeTypeAdaptabilityTest#computedPropertyMethodDeclarationDoesNotThrowreproduces the UOE onmainand passes on this branch../gradlew :rewrite-java-test:test --tests org.openrewrite.java.ChangeTypeTest— 81 tests, all pass../gradlew :rewrite-javascript:integTest --tests org.openrewrite.javascript.ChangeTypeAdaptabilityTest— 2 tests, all pass../gradlew assemble— clean build across all modules../gradlew :rewrite-javascript:test— green.