Java Launcher does not fail when running compact java-file with private no-arg constructor

XMLWordPrintable

    • Fix Understood

      JEP 512 reads:

      "If the chosen method is static then the launcher invokes it.

      Otherwise, the chosen method is an instance main method. The class must have a non-private constructor with no parameters. The launcher invokes that constructor and then invokes the chosen main method of the resulting object. If there is no such constructor then the launcher reports an error and terminates."

      However:
      {noformat}
      samael:nutshell-examples ben$ java -version
      openjdk version "25" 2025-09-16 LTS
      OpenJDK Runtime Environment Temurin-25+36 (build 25+36-LTS)
      OpenJDK 64-Bit Server VM Temurin-25+36 (build 25+36-LTS, mixed mode, sharing)

      samael:nutshell-examples ben$ cat HelloWorld.java class HelloWorld {
          private HelloWorld() {}

          void main() {
              System.out.println("Hello, World!");
          }
      }

      samael:nutshell-examples ben$ java HelloWorld.java
      Hello, World!
      {noformat}

            Assignee:
            Christian Stein
            Reporter:
            Robert Scholte
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: