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

JEP 463 (implicitly declared classes) does not play well with JEP 330 (shebangs)

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      ADDITIONAL SYSTEM INFORMATION :
      $ java -version
      openjdk version "25-ea" 2025-09-16
      OpenJDK Runtime Environment (build 25-ea+16-Ubuntu-1)
      OpenJDK 64-Bit Server VM (build 25-ea+16-Ubuntu-1, mixed mode, sharing)
      $ cat /etc/os-release
      PRETTY_NAME="Ubuntu 25.04"
      NAME="Ubuntu"
      VERSION_ID="25.04"
      VERSION="25.04 (Plucky Puffin)"
      VERSION_CODENAME=plucky
      ID=ubuntu
      ID_LIKE=debian
      HOME_URL="https://www.ubuntu.com/"
      SUPPORT_URL="https://help.ubuntu.com/"
      BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
      PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
      UBUNTU_CODENAME=plucky
      LOGO=ubuntu-logo

      A DESCRIPTION OF THE PROBLEM :
      It seems reasonable to assume that a script with an implicitly declared main class should be runnable directly with a shebang. Unfortunately, this does not work out of the box because adding a shebang line breaks this feature.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      $ chmod +x test.java
      $ ./test.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Hello, world!
      ACTUAL -
      error: no class declared in source file

      ---------- BEGIN SOURCE ----------
      #!/usr/bin/java --enable-preview

      void main() {
      IO.println("Hello, world!");
      }
      ---------- END SOURCE ----------

            cstein Christian Stein
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: