8328339: Static import prevents source launcher from finding class with main method

Reviewed-by: jlahoda
This commit is contained in:
Christian Stein 2024-03-22 05:29:20 +00:00
parent 256d48b196
commit 9bc741d04f
4 changed files with 67 additions and 53 deletions

View file

@ -23,7 +23,7 @@
/*
* @test
* @bug 8192920 8204588 8246774 8248843 8268869 8235876
* @bug 8192920 8204588 8246774 8248843 8268869 8235876 8328339
* @summary Test source launcher
* @library /tools/lib
* @enablePreview
@ -110,6 +110,27 @@ public class SourceLauncherTest extends TestRunner {
testSuccess(base.resolve("hello").resolve("World.java"), "Hello World! [1, 2, 3]\n");
}
@Test
public void testHelloWorldInPackageWithStaticImport(Path base) throws IOException {
tb.writeJavaFiles(base,
"""
package hello;
import static hello.Helper.*;
import java.util.Arrays;
class World {
public static void main(String... args) {
m(args);
}
}
class Helper {
static void m(String... args) {
System.out.println("Hello World! " + Arrays.toString(args));
}
}
""");
testSuccess(base.resolve("hello").resolve("World.java"), "Hello World! [1, 2, 3]\n");
}
@Test
public void testHelloWorldWithAux(Path base) throws IOException {
tb.writeJavaFiles(base,
@ -300,7 +321,7 @@ public class SourceLauncherTest extends TestRunner {
public void testMismatchOfPathAndPackage(Path base) throws IOException {
Files.createDirectories(base);
Path file = base.resolve("MismatchOfPathAndPackage.java");
Files.write(file, List.of("package p;"));
Files.write(file, List.of("package p; class MismatchOfPathAndPackage {}"));
testError(file, "", "error: end of path to source file does not match its package name p: " + file);
}