Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#1,289 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
build-system

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Java
Estrellas
156
Forks
129
Merge medio
7 h 12 min
PR fusionados (30 d)
43

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de openrewrite/rewrite-migrate-java

Todos los issues de openrewrite/rewrite-migrate-java

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.