Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`ExtractExplicitConstructorInvocationArguments` drops the extracted variable declaration when run via rewrite-maven-plugin

未关闭
#1,289 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
build-system

调研方向

Start by reading the ExtractExplicitConstructorInvocationArguments recipe and its extractMethodInvocationArgument test, which the issue says passes. Compare the test’s rewrite result with a run through rewrite-maven-plugin 6.46.1 using the supplied Java 25 example. Done means the extracted variable declaration appears before the explicit super or this invocation, so the transformed source compiles.

由索引模型根据 Issue 内容生成。

描述

What version of OpenRewrite are you using?
  • rewrite-maven-plugin 6.46.1
  • rewrite-migrate-java 3.42.1 (latest published on Maven Central)
  • Java 25 (maven.compiler.release=25)
What is the smallest, simplest way to reproduce the problem?

pom.xml with only this recipe active:

<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <version>6.46.1</version>
  <configuration>
    <activeRecipes>
      <recipe>org.openrewrite.java.migrate.lang.ExtractExplicitConstructorInvocationArguments</recipe>
    </activeRecipes>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.openrewrite.recipe</groupId>
      <artifactId>rewrite-migrate-java</artifactId>
      <version>3.42.1</version>
    </dependency>
  </dependencies>
</plugin>

Source (this is the input of the recipe's own extractMethodInvocationArgument test):

import java.util.Objects;

class Parent {
    Parent(String name) {
    }
}

class Child extends Parent {
    Child(String name) {
        super(Objects.requireNonNull(name));
    }
}

Run mvn rewrite:run.

What did you expect to see?
Child(String name) {
    String name1 = Objects.requireNonNull(name);
    super(name1);
}
What did you see instead?
Child(String name) {
    super(name1);
}

The argument is replaced by a reference to a local variable, but the declaration is never inserted, so the result does not compile (cannot find symbol: variable name1).

The same happens with this(..) delegation (this(Executors.newSingleThreadScheduledExecutor()) becomes this(s1)) and with static calls (super(String.valueOf(1)) becomes super(v)). It is not specific to lambdas.

Additional context
  • The corresponding unit test passes upstream, so the problem seems specific to a real run through the Maven plugin rather than RewriteTest.
  • I could not test 3.46.0, since it is not yet on Maven Central. The only commit touching the recipe between 3.42.1 and 3.46.0 is #1235 (skip non-Java sources), which looks unrelated.
  • No existing issue found for this recipe.
主要语言
Java
星标
159
派生
130
平均合并
7 小时 12 分钟
30 天内合并 PR
43

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openrewrite/rewrite-migrate-java 的其他 Issue

查看 openrewrite/rewrite-migrate-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。