8344647: Make java.se participate in the preview language feature requires transitive java.base

Reviewed-by: asotona, darcy
This commit is contained in:
Jan Lahoda 2024-12-18 09:58:40 +00:00
parent 9e8aa855fe
commit d50b725ac0
8 changed files with 57 additions and 10 deletions

View file

@ -155,7 +155,6 @@ module java.base {
exports jdk.internal.javac to exports jdk.internal.javac to
java.compiler, java.compiler,
java.desktop, // for ScopedValue java.desktop, // for ScopedValue
java.se, // for ParticipatesInPreview
jdk.compiler, jdk.compiler,
jdk.incubator.vector, // participates in preview features jdk.incubator.vector, // participates in preview features
jdk.jartool, // participates in preview features jdk.jartool, // participates in preview features

View file

@ -23,8 +23,6 @@
* questions. * questions.
*/ */
import jdk.internal.javac.ParticipatesInPreview;
/** /**
* Defines the API of the Java SE Platform. * Defines the API of the Java SE Platform.
* *
@ -40,7 +38,6 @@ import jdk.internal.javac.ParticipatesInPreview;
* @moduleGraph * @moduleGraph
* @since 9 * @since 9
*/ */
@ParticipatesInPreview
module java.se { module java.se {
requires transitive java.base; requires transitive java.base;
requires transitive java.compiler; requires transitive java.compiler;

View file

@ -76,7 +76,7 @@ public abstract class Directive implements ModuleElement.Directive {
@Override @Override
public String toString() { public String toString() {
return String.format("ACC_%s (0x%04x", name(), value); return String.format("ACC_%s (0x%04x)", name(), value);
} }
} }

View file

@ -152,7 +152,9 @@ public class Preview {
// s participates in the preview API // s participates in the preview API
return syms.java_base.exports.stream() return syms.java_base.exports.stream()
.filter(ed -> ed.packge.fullname == names.jdk_internal_javac) .filter(ed -> ed.packge.fullname == names.jdk_internal_javac)
.anyMatch(ed -> ed.modules.contains(m)); .anyMatch(ed -> ed.modules.contains(m)) ||
//the specification lists the java.se module as participating in preview:
m.name == names.java_se;
} }
/** /**

View file

@ -3887,7 +3887,7 @@ compiler.misc.cant.resolve.modules=\
cannot resolve modules cannot resolve modules
compiler.misc.bad.requires.flag=\ compiler.misc.bad.requires.flag=\
bad requires flag: {0} invalid flag for "requires java.base": {0}
# 0: string # 0: string
compiler.err.invalid.module.specifier=\ compiler.err.invalid.module.specifier=\

View file

@ -127,6 +127,7 @@ public class Names {
// module names // module names
public final Name java_base; public final Name java_base;
public final Name java_se;
public final Name jdk_unsupported; public final Name jdk_unsupported;
// attribute names // attribute names
@ -315,6 +316,7 @@ public class Names {
// module names // module names
java_base = fromString("java.base"); java_base = fromString("java.base");
java_se = fromString("java.se");
jdk_unsupported = fromString("jdk.unsupported"); jdk_unsupported = fromString("jdk.unsupported");
// attribute names // attribute names

View file

@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 8328481 8332236 8332890 * @bug 8328481 8332236 8332890 8344647
* @summary Check behavior of module imports. * @summary Check behavior of module imports.
* @library /tools/lib * @library /tools/lib
* @modules java.logging * @modules java.logging
@ -33,7 +33,7 @@
* jdk.compiler/com.sun.tools.javac.util * jdk.compiler/com.sun.tools.javac.util
* @build toolbox.ToolBox toolbox.JavacTask * @build toolbox.ToolBox toolbox.JavacTask
* @run main ImportModule * @run main ImportModule
*/ */
import com.sun.source.tree.Tree; import com.sun.source.tree.Tree;
import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskEvent;
@ -829,6 +829,7 @@ public class ImportModule extends TestRunner {
} }
} }
@Test
public void testPackageImportDisambiguates(Path base) throws Exception { public void testPackageImportDisambiguates(Path base) throws Exception {
Path current = base.resolve("."); Path current = base.resolve(".");
Path src = current.resolve("src"); Path src = current.resolve("src");
@ -919,4 +920,50 @@ public class ImportModule extends TestRunner {
.run(Task.Expect.SUCCESS) .run(Task.Expect.SUCCESS)
.writeAll(); .writeAll();
} }
@Test //JDK-8344647
public void testJavaBaseOverride(Path base) throws Exception {
Path current = base.resolve(".");
Path src = current.resolve("src");
Path javaBaseClasses = current.resolve("javaBaseClasses");
Path javaBase = src.resolve("java.base");
tb.writeJavaFiles(javaBase,
"""
module java.base {
exports java.lang;
}
""",
"""
package java.lang;
public class Object {}
""");
Files.createDirectories(javaBaseClasses);
new JavacTask(tb)
.options("--patch-module", "java.base=" + src.toString())
.outdir(javaBaseClasses)
.files(tb.findJavaFiles(src))
.run(Task.Expect.SUCCESS)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
Path test = current.resolve("test");
tb.writeJavaFiles(test,
"""
module test {
requires java.se;
}
""");
Path classes = current.resolve("classes");
Files.createDirectories(classes);
new JavacTask(tb)
.options("--patch-module", "java.base=" + javaBaseClasses.toString())
.outdir(classes)
.files(tb.findJavaFiles(test))
.run(Task.Expect.SUCCESS)
.writeAll();
}
} }

View file

@ -804,7 +804,7 @@ public class AnnotationsOnModules extends ModuleTestBase {
.writeAll() .writeAll()
.getOutputLines(OutputKind.DIRECT); .getOutputLines(OutputKind.DIRECT);
List<String> expectedErrors = List.of( List<String> expectedErrors = List.of(
"- compiler.err.cant.access: m.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.bad.requires.flag: ACC_TRANSITIVE (0x0020))", "- compiler.err.cant.access: m.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.bad.requires.flag: ACC_TRANSITIVE (0x0020)))",
"1 error" "1 error"
); );