8379083: Executable source program should ignore module declaration

Reviewed-by: jlamperth, liach
This commit is contained in:
Christian Stein 2026-05-29 07:22:20 +00:00
parent 9f38c8b739
commit ebc3af7a2d
2 changed files with 8 additions and 3 deletions

View File

@ -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<String> computePackageNames() {

View File

@ -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