Drop the rewrite-analysis dependency from URLConstructorToURICreate - #1226
Merged
Conversation
A single recipe pulled in the whole module, only to resolve a `String` identifier back to the literal it was initialized with. Walking the enclosing blocks for the matching variable declaration covers the fields and locals that the recipe actually sees, and it drops the `RecipeRunException` catch that was there solely because `ConstantFold` throws on a lambda parameter. The lookup is by name rather than by dataflow, so a variable reassigned before use, or shadowed elsewhere, can now fold to a different value. That only shifts whether the path is judged valid; the argument is passed through to `URI.create` untouched either way.
Matching the declaration on its name alone crossed two boundaries the previous `ConstantFold` respected. A local shadowing a field is a distinct variable, so comparing `JavaType.Variable` — which carries the owner — keeps the walk going past the shadowing declaration to the one the identifier actually binds to. And a variable written to anywhere in the file no longer holds the value it was declared with, which is the condition `ConstantFold` expressed as a single assigned value. An assignment through `this` reaches the same variable as a bare name, so the target is unwrapped before comparing.
timtebeek
marked this pull request as ready for review
August 25, 2026 21:41
MBoegers
approved these changes
Aug 26, 2026
Contributor
There was a problem hiding this comment.
This will not work for external constants Assume:
// src/main/Constants.java
public class Constants {
public static final String requestURL = "..";
//...
}where Constants.requestURL is used in different locations.
Not common, as it breaks configurability and multiple coding best practices, but still possible to encounter in small tools.
Okay to remove the overhead but want to flag the new gap.
Member
Author
|
Indeed a known gap, much as we saw on the rewrite-spring module as well: |
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.
URLConstructorToURICreatewas the only consumer oforg.openrewrite.meta:rewrite-analysis, usingConstantFoldto resolve aStringidentifier back to the literal it was initialized with. That lookup is now a walk over the enclosing blocks for the matching variable declaration, which drops theRecipeRunExceptioncatch that existed solely becauseConstantFoldthrows on a lambda parameter.To keep the previous behaviour, the walk matches on
JavaType.Variablerather than on the name — the owner distinguishes a local shadowing a field from the field itself — and refuses to fold a variable that is assigned to anywhere in the file, including throughthis, which is the conditionConstantFoldexpressed as a single assigned value.Tests cover the local-variable case that was previously untested, plus the reassigned, shadowed-field, and reassigned-through-
thiscases; all 14 pass.