Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8328339

Static import prevents source launcher from finding class with main method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • 17, 21, 22, 23
    • tools
    • 11
    • b16

      This single-file program stored in `test/Main.java`:
      ```
      package test;

      import static test.Helper.*;

      public class Main {
      public static void main(String[] args) {
      m();
      }
      }

      class Helper {
      static void m() {}
      }
      ```
      yields `error: can't find main(String[]) method in class: test.Helper` running via `java test/Main.java` on Java 11 up to 21. Error message for Java 22 reads slightly different: `error: can't find class: Main`.

      Workaround: remove `import static test.Helper.*;` and use `Helper.m();` inside Main's main method.

            cstein Christian Stein
            cstein Christian Stein
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: