Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng
#1,289 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #1297 của @timtebeek — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
build-system

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
Java
Star
159
Fork
130
Merge trung bình
6 giờ 49 phút
Pull request đã merge (30 ngày)
47

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openrewrite/rewrite-migrate-java

Tất cả issue của openrewrite/rewrite-migrate-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.