From 2cc14faa21b32e594d5f8630f2e02daa9085b01f Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Wed, 18 Dec 2024 13:45:44 +0000 Subject: [PATCH] 8344647: Make java.se participate in the preview language feature `requires transitive java.base` Reviewed-by: liach, vromero Backport-of: d50b725ac0f228f5b04dd68c123c7f6b263c0d02 --- src/java.base/share/classes/module-info.java | 1 - src/java.se/share/classes/module-info.java | 3 -- .../com/sun/tools/javac/code/Directive.java | 2 +- .../com/sun/tools/javac/code/Preview.java | 4 +- .../tools/javac/resources/compiler.properties | 2 +- .../com/sun/tools/javac/util/Names.java | 2 + test/langtools/tools/javac/ImportModule.java | 51 ++++++++++++++++++- .../javac/modules/AnnotationsOnModules.java | 2 +- 8 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index 3c293770003..5b0117a1efc 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.java @@ -155,7 +155,6 @@ exports jdk.internal.javac to java.compiler, java.desktop, // for ScopedValue - java.se, // for ParticipatesInPreview jdk.compiler, jdk.incubator.vector, // participates in preview features jdk.jartool, // participates in preview features diff --git a/src/java.se/share/classes/module-info.java b/src/java.se/share/classes/module-info.java index 9a2704660b7..5dbf65830e3 100644 --- a/src/java.se/share/classes/module-info.java +++ b/src/java.se/share/classes/module-info.java @@ -23,8 +23,6 @@ * questions. */ -import jdk.internal.javac.ParticipatesInPreview; - /** * Defines the API of the Java SE Platform. * @@ -40,7 +38,6 @@ * @moduleGraph * @since 9 */ -@ParticipatesInPreview module java.se { requires transitive java.base; requires transitive java.compiler; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java index cf942dab5cd..f41866ddb6a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java @@ -76,7 +76,7 @@ public static int value(Set s) { @Override public String toString() { - return String.format("ACC_%s (0x%04x", name(), value); + return String.format("ACC_%s (0x%04x)", name(), value); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java index c66e1758616..3879f72ff30 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java @@ -150,7 +150,9 @@ public boolean participatesInPreview(Symtab syms, ModuleSymbol m) { // s participates in the preview API return syms.java_base.exports.stream() .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; } /** diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index 96944f698dd..5d3bf557a20 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -3770,7 +3770,7 @@ compiler.misc.cant.resolve.modules=\ cannot resolve modules compiler.misc.bad.requires.flag=\ - bad requires flag: {0} + invalid flag for "requires java.base": {0} # 0: string compiler.err.invalid.module.specifier=\ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java index 6c48490cf16..d9aec7c4592 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java @@ -127,6 +127,7 @@ public static Names instance(Context context) { // module names public final Name java_base; + public final Name java_se; public final Name jdk_unsupported; // attribute names @@ -315,6 +316,7 @@ public Names(Context context) { // module names java_base = fromString("java.base"); + java_se = fromString("java.se"); jdk_unsupported = fromString("jdk.unsupported"); // attribute names diff --git a/test/langtools/tools/javac/ImportModule.java b/test/langtools/tools/javac/ImportModule.java index 1224a9d7470..ac00ea823f1 100644 --- a/test/langtools/tools/javac/ImportModule.java +++ b/test/langtools/tools/javac/ImportModule.java @@ -23,7 +23,7 @@ /** * @test - * @bug 8328481 8332236 8332890 + * @bug 8328481 8332236 8332890 8344647 * @summary Check behavior of module imports. * @library /tools/lib * @modules java.logging @@ -33,7 +33,7 @@ * jdk.compiler/com.sun.tools.javac.util * @build toolbox.ToolBox toolbox.JavacTask * @run main ImportModule -*/ + */ import com.sun.source.tree.Tree; import com.sun.source.util.TaskEvent; @@ -829,6 +829,7 @@ public class Test { } } + @Test public void testPackageImportDisambiguates(Path base) throws Exception { Path current = base.resolve("."); Path src = current.resolve("src"); @@ -919,4 +920,50 @@ public class Test { .run(Task.Expect.SUCCESS) .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(); + } } diff --git a/test/langtools/tools/javac/modules/AnnotationsOnModules.java b/test/langtools/tools/javac/modules/AnnotationsOnModules.java index 65019854360..291633b4fb2 100644 --- a/test/langtools/tools/javac/modules/AnnotationsOnModules.java +++ b/test/langtools/tools/javac/modules/AnnotationsOnModules.java @@ -804,7 +804,7 @@ public class C {} .writeAll() .getOutputLines(OutputKind.DIRECT); List 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" );