Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,289 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
build-system

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Java
Stelle
156
Fork
129
Merge medio
7h 12m
PR unite (30g)
43

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openrewrite/rewrite-migrate-java

Tutte le issue di openrewrite/rewrite-migrate-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.