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

Launcher error message unhelpful when instance main method has no void modifier

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 23
    • tools
    • None

      $ java --version
      openjdk 23 2024-09-17
      OpenJDK Runtime Environment (build 23+37-2369)
      OpenJDK 64-Bit Server VM (build 23+37-2369, mixed mode, sharing)
      $ cat Hello.java
      main() {
          println("Hello");
      }
      $ java --enable-preview Hello.java
      error: no class declared in source file
      $ cat Hello2.java
      void main() {
          println("Hello");
      }
      $ java --enable-preview Hello2.java
      Hello
      $

      It’s true that Hello.java does not declare a class, since the void modifier is missing from the instance main method. The error message, however, gives no hint of that reason. It would be far more helpful if it said something like “void modifier required in declaration of instance main method”.

            Unassigned Unassigned
            mr Mark Reinhold
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: