Filed https://bugs.openjdk.org/browse/JDK-8398778. I've also tried
what you seem to have suggested:
diff --git a/src/java.base/share/native/libjli/java.c
b/src/java.base/share/native/libjli/java.c
index 0df8a9a3543..93c55d77503 100644
--- a/src/java.base/share/native/libjli/java.c
+++ b/src/java.base/share/native/libjli/java.c
@@ -1403,7 +1403,7 @@ ParseArguments(int *pargc, char ***pargv,
if (mode == LM_SOURCE) {
// communicate the launcher mode to runtime
AddOption("-Dsun.java.launcher.mode=source", NULL);
- AddOption("--add-modules=ALL-DEFAULT", NULL);
+ AddOption("--add-modules=jdk.compiler,ALL-DEFAULT", NULL);
*pwhat = SOURCE_LAUNCHER_MAIN_ENTRY;
// adjust (argc, argv) so that the name of the source file
// is included in the args passed to the source launcher
As a result, I could see this:
% ./bin/java X.java
Error occurred during initialization of boot layer
java.lang.module.FindException: Module jdk.compiler not found
This seems marginally better than the message before.
On Tue, Dec 1, 2026 at 5:32 PM Alan Bateman <[email protected]> wrote:
>
> On 01/12/2026 16:12, Pavel Rappo wrote:
>
> There have been reports (e.g. [^1]) that in some runtime images java
> cannot run source files. Here's another scenario.
>
> If a source file is run by the java command from a jlink-built runtime
> image that doesn't include jdk.compiler, the output will read:
>
> ./java X.java
> Error: A JNI error has occurred, please check your installation
> and try again
> Exception in thread "main" java.lang.InternalError: Module
> jdk.compiler not in boot Layer
> at
> java.base/sun.launcher.LauncherHelper.loadModuleMainClass(LauncherHelper.java:807)
> at
> java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:757)
>
> I accept that the inability to run a source file is not exactly
> unexpected in such circumstances. However, the usage output for the
> java command suggests that this capability is __integral__:
>
> Usage: java [java options...] <application> [application arguments...]
>
> Where <application> is one of:
> <mainclass> to execute the main method of a
> compiled main class
> -jar <jarfile>.jar to execute the main class of a JAR archive
> -m <module>[/<mainclass>] to execute the main class of a module
> <sourcefile>.java to compile and execute a source-file program
>
> Can you create a bug for this? And if you have cycles, can you see if
> changing ParseArguments (in java.c) to add --add-modules=jdk.compiler when
> the mode is LM_SOURCE (you'll see it adds ALL-DEFAULT already). That would at
> least give you an error that the jdk.compiler is not found. We can do better
> than that but try that first. Making part of the usage message conditional
> would require further work of course.
>
> -Alan