Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
/// Has, as its members, the fields and methods in the compact source file; and
/// Must have a launchable main method; if it does not, a compile-time error is reported.
void main() {
IO.println("Compact source file & main method here ...");
IO.println("Compact source file & main method here ..."); // IO (java.io) needs no import
IO.println("Items: " + List.of("a", "b", "c")); // List (java.util) needs no import either
}
23 changes: 23 additions & 0 deletions JavaReleases/src/test/java/pl/mperor/lab/java/Java25.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.junit.jupiter.api.Test;
import pl.mperor.lab.common.TestUtils;

import java.io.IOException;
import java.nio.file.Path;
import java.util.NoSuchElementException;

/// Java 25 (September 2025)
Expand Down Expand Up @@ -164,4 +166,25 @@ public void testModuleImportAmbiguityResolvedBySingleTypeImport() {
Assertions.assertEquals(java.util.List.of("John Doe", "Jane Doe"), demo.names);
}

/// CompactSourceFile.java has no package declaration, so it lives in the unnamed package and
/// cannot be imported here (a named package can never import from the unnamed one). It is
/// launched the way JEP 512 intends: directly by the `java` source launcher, one file, no build step.
@Test
public void testCompactSourceFileRunsDirectlyViaSourceLauncher() throws IOException, InterruptedException {
var javaLauncher = Path.of(System.getProperty("java.home"), "bin", "java");
var sourceFile = Path.of("src", "main", "java", "pl", "mperor", "lab", "java", "CompactSourceFile.java");

var process = new ProcessBuilder(javaLauncher.toString(), sourceFile.toString())
.redirectErrorStream(true)
.start();
String output = new String(process.getInputStream().readAllBytes());
int exitCode = process.waitFor();

Assertions.assertEquals(0, exitCode, output);
Assertions.assertEquals(
"Compact source file & main method here ..." + System.lineSeparator()
+ "Items: [a, b, c]" + System.lineSeparator(),
output);
}

}
Loading