Skip to content

MigrateMainMethodToInstanceMain changes main method referenced as static API #1083

@protocol7

Description

@protocol7

What version of OpenRewrite are you using?

  • rewrite-migrate-java: 3.34.0
  • rewrite-core: 8.81.1
  • rewrite-java: 8.81.1

What is the smallest, simplest way to reproduce the problem?

class Main {
  public static void main(String[] args) {}
}
class MainTest {
  void test() {
    Main.main(new String[] {});
  }
}

Run org.openrewrite.java.migrate.lang.MigrateMainMethodToInstanceMain.

What did you expect to see?

The public static void main(String[] args) method should be preserved when it is referenced directly as a static API from another source file.

What did you see instead?

The recipe changes the main method to an instance no-arg method:

class Main {
  void main() {}
}

But the call site is left unchanged:

class MainTest {
  void test() {
    Main.main(new String[] {});
  }
}

The rewritten code no longer compiles:

method main in class Main cannot be applied to given types;
  required: no arguments
  found:    String[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions