Repository navigation
Fix ExtractExplicitConstructorInvocationArguments dropping extracted declarations - #1297
Merged
Merged
Conversation
…declarations A constructor invocation is typed as returning the constructed class, so the context-free template treated super(..)/this(..) as an expression and silently dropped the inserted declarations, leaving references to undeclared variables. Fixes #1289
timtebeek
marked this pull request as ready for review
October 15, 2026 14:50
This was referenced Oct 16, 2026
Merged
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.
ExtractExplicitConstructorInvocationArgumentsdrops the extracted variable declaration when run via rewrite-maven-plugin #1289.Problem
ExtractExplicitConstructorInvocationArgumentsreplacedsuper(..)/this(..)arguments with references to new local variables, but never inserted the declarations, so the result didn't compile:The root cause was in
JavaTemplate, which treated the constructor call as an expression and silently dropped the inserted statements. That is fixed upstream in openrewrite/rewrite#9206, which this PR relies on.Changes
extractWithSourcePathWideningSupertypethat also matched a constructor parameter.Why the tests didn't catch it
The test class is gated on
@EnabledForJreRange(min = JAVA_25), and CI runs tests on an older JVM, so all of them are skipped. When run on Java 25, the existing tests fail without these changes, and all 20 pass with them.