JDK-8366730 : JEP 463 (implicitly declared classes) does not play well with JEP 330 (shebangs)
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 25
  • Priority: P5
  • Status: New
  • Resolution: Unresolved
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2025-09-02
  • Updated: 2025-09-02
Description
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 ----------


Comments
Issue was reproduced with the test case.
02-09-2025

Impact - L ( minimal impact, rare usage) Likelihood - L ( uncommon use cae) Workaround - H ( no workaround) Priority - P5
02-09-2025