From ebc3af7a2da3d1c903159b344ce46d40ca9fc9dd Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 29 May 2026 07:22:20 +0000 Subject: [PATCH] 8379083: Executable source program should ignore module declaration Reviewed-by: jlamperth, liach --- .../com/sun/tools/javac/launcher/ProgramDescriptor.java | 5 +++-- test/langtools/tools/javac/launcher/SourceLauncherTest.java | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/ProgramDescriptor.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/ProgramDescriptor.java index fd99838427b..8589b916504 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/ProgramDescriptor.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/ProgramDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -114,7 +114,8 @@ public record ProgramDescriptor( } public boolean isModular() { - return Files.exists(sourceRootPath.resolve("module-info.java")); + return !fileObject.isFirstLineIgnored() // programs with "shebang" lines are never modular + && Files.exists(sourceRootPath.resolve("module-info.java")); } public Set computePackageNames() { diff --git a/test/langtools/tools/javac/launcher/SourceLauncherTest.java b/test/langtools/tools/javac/launcher/SourceLauncherTest.java index d0cf11a0327..0f912b74cdf 100644 --- a/test/langtools/tools/javac/launcher/SourceLauncherTest.java +++ b/test/langtools/tools/javac/launcher/SourceLauncherTest.java @@ -24,7 +24,7 @@ /* * @test * @bug 8192920 8204588 8246774 8248843 8268869 8235876 8328339 8335896 8344706 - * 8362237 8376534 + * 8362237 8376534 8379083 * @summary Test source launcher * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api @@ -159,6 +159,10 @@ public class SourceLauncherTest extends TestRunner { "}"); Files.copy(base.resolve("HelloWorld.java"), base.resolve("HelloWorld")); testSuccess(base.resolve("HelloWorld"), "Hello World! [1, 2, 3]\n"); + + // Re-run with a "stray" module descriptor being ignored + Files.writeString(base.resolve("module-info.java"), "module stray {}"); + testSuccess(base.resolve("HelloWorld"), "Hello World! [1, 2, 3]\n"); } @Test