Skip to content

Commit 3b360ac

Browse files
author
duke
committedMar 13, 2024
Automatic merge of jdk:master into master
2 parents 461b324 + 3b18c5d commit 3b360ac

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed
 

‎src/java.base/share/man/java.1

+5
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ the compilation.
279279
This sets both the source version accepted by compiler and the system
280280
API that may be used by the code in the source file.
281281
.IP \[bu] 2
282+
If \f[V]--enable-preview\f[R] is specified, the \f[V]--source N\f[R]
283+
arguments can be omitted.
284+
If the Java runtime version is \f[V]N\f[R], then \f[V]--release N\f[R]
285+
is implied when compiling source files.
286+
.IP \[bu] 2
282287
If a \f[V]module-info.java\f[R] file exists in the
283288
\f[V]<source-root>\f[R] directory, its module declaration is used to
284289
define a named module that will contain all the classes compiled from

‎src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/RelevantJavacOptions.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -112,7 +112,9 @@ static RelevantJavacOptions of(ProgramDescriptor program, String... runtimeArgs)
112112
programOptions.add(opt);
113113
subsequentOptions.add(opt);
114114
if (sourceOpt == null) {
115-
throw new Fault(Errors.EnablePreviewRequiresSource);
115+
String feature = String.valueOf(Runtime.version().feature());
116+
programOptions.addAll(List.of("--release", feature));
117+
subsequentOptions.addAll(List.of("--release", feature));
116118
}
117119
}
118120
default -> {

‎src/jdk.compiler/share/classes/com/sun/tools/javac/resources/launcher.properties

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -139,9 +139,6 @@ launcher.err.no.value.for.option=\
139139
launcher.err.invalid.value.for.source=\
140140
invalid value for --source option: {0}
141141

142-
launcher.err.enable.preview.requires.source=\
143-
--enable-preview must be used with --source
144-
145142
launcher.err.unnamed.pkg.not.allowed.named.modules=\
146143
unnamed package is not allowed in named modules
147144

‎test/langtools/tools/javac/launcher/BasicSourceLauncherTests.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -100,11 +100,7 @@ void main() {
100100
}
101101
""");
102102

103-
// Replace with plain Run.of(hi) once implict classes are out of preview
104-
System.setProperty("jdk.internal.javac.source", String.valueOf(Runtime.version().feature()));
105103
var run = Run.of(hi, List.of("--enable-preview"), List.of());
106-
System.clearProperty("jdk.internal.javac.source");
107-
108104
assertAll("# " + run,
109105
() -> assertLinesMatch(
110106
"""

‎test/langtools/tools/javac/launcher/SourceLauncherTest.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,12 +51,9 @@
5151
import java.nio.file.Paths;
5252
import java.util.ArrayList;
5353
import java.util.Collections;
54-
import java.util.HashMap;
55-
import java.util.Map;
5654
import java.util.List;
5755
import java.util.Properties;
5856
import java.util.regex.Pattern;
59-
import java.util.stream.Collectors;
6057

6158
import com.sun.tools.javac.launcher.SourceLauncher;
6259
import com.sun.tools.javac.launcher.Fault;
@@ -534,10 +531,9 @@ public void testEnablePreviewNoSource(Path base) throws IOException {
534531
List<String> log = new JavaTask(tb)
535532
.vmOptions("--enable-preview")
536533
.className(base.resolve("HelloWorld.java").toString())
537-
.run(Task.Expect.FAIL)
538-
.getOutputLines(Task.OutputKind.STDERR);
539-
log = log.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
540-
checkEqual("stderr", log, List.of("error: --enable-preview must be used with --source"));
534+
.run(Task.Expect.SUCCESS)
535+
.getOutputLines(Task.OutputKind.STDOUT);
536+
checkEqual("stdout", log, List.of("Hello World! []"));
541537
}
542538

543539
@Test

0 commit comments

Comments
 (0)
Please sign in to comment.