Skip to content

Preserve Java 25 constructor extraction statements - #1206

Draft
martinfrancois wants to merge 1 commit into
openrewrite:mainfrom
martinfrancois:agent/repro-extract-constructor-undefined-locals
Draft

Preserve Java 25 constructor extraction statements#1206
martinfrancois wants to merge 1 commit into
openrewrite:mainfrom
martinfrancois:agent/repro-extract-constructor-undefined-locals

Conversation

@martinfrancois

@martinfrancois martinfrancois commented Aug 15, 2026

Copy link
Copy Markdown

Suggested review order: 18 of 52 (Score: 6.5)
Review first: openrewrite/rewrite-static-analysis#976

What's changed?

Preserves the local declarations inserted before Java 25 explicit constructor invocations. The recipe now replaces the constructor arguments before inserting the Java 25 statements, allowing both transformations to use JavaTemplate without reparsing away the declarations.

What's your motivation?

Recipe: org.openrewrite.java.migrate.lang.ExtractExplicitConstructorInvocationArguments.

I found this by running org.openrewrite.java.migrate.lang.ExtractExplicitConstructorInvocationArguments from org.openrewrite.recipe:rewrite-migrate-java:3.40.0 on CodexAppServerClient.java in Symphony-Trello at a8013f27 with Java 25. I reproduced the same result with the latest released recipe artifact, org.openrewrite.recipe:rewrite-migrate-java:3.42.0. The recipe changed 11 files, and ./mvnw -DskipTests compile then reported undefined generated identifiers in production code.

Before

public CodexAppServerClient(ObjectMapper json, TrelloHandoffToolHandler trelloTools) {
    this(json, trelloTools, ApplicationClock.systemUtc());
}

Actual after the recipe

public CodexAppServerClient(ObjectMapper json, TrelloHandoffToolHandler trelloTools) {
    this(json, trelloTools, clock1);
}

Expected after the recipe

public CodexAppServerClient(ObjectMapper json, TrelloHandoffToolHandler trelloTools) {
    Clock clock1 = ApplicationClock.systemUtc();
    this(json, trelloTools, clock1);
}

The transformed constructor references clock1 without declaring it. The same mechanism generated other missing names, including workflowConfig1, healthChecker1, and repositorySources1, so the checkout no longer compiles.

Confirmed real-world execution

Anything in particular you'd like reviewers to focus on?

Please review the transformation order. Replacing arguments first lets the pre-Java-25 parse shape remain valid for that template; inserting the Java 25 declarations last preserves them. The Java-25-only focused suite passes with both steps implemented through JavaTemplate.

Have you considered any alternatives or workarounds?

Constructing identifiers and variable declarations directly avoids the reparse, but OpenRewrite's template abstraction provides attributed nodes and preserves framework conventions when the operations are ordered safely.

Any additional context

Pre-existing tests changed: ExtractExplicitConstructorInvocationArgumentsTest.java.extractWithSourcePathWideningSupertype (updated).

  • Target commit: martinfrancois/symphony-trello@a8013f27
  • Discovery release: org.openrewrite.recipe:rewrite-migrate-java:3.40.0
  • Latest verification release: org.openrewrite.recipe:rewrite-migrate-java:3.42.0
  • Target verification: the baseline compiles; the transformed checkout reports missing generated variables in 11 files
  • Focused tests: ExtractExplicitConstructorInvocationArgumentsTest, enabled only on Java 25 or later

This change was prepared with AI assistance. I reviewed the target execution evidence, implementation, tests, and contribution text.

Checklist

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 15, 2026
@martinfrancois martinfrancois changed the title Declare extracted constructor-invocation arguments Preserve Java 25 constructor extraction statements Aug 15, 2026
@martinfrancois
martinfrancois force-pushed the agent/repro-extract-constructor-undefined-locals branch 2 times, most recently from 9d9ca3a to 412694d Compare August 16, 2026 02:53
@martinfrancois
martinfrancois force-pushed the agent/repro-extract-constructor-undefined-locals branch from 412694d to d2f4a8d Compare August 16, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant