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
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

View file

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

View file

@ -76,7 +76,7 @@ public abstract class Directive implements ModuleElement.Directive {
@Override
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
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;
}
/**

View file

@ -3887,7 +3887,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=\

View file

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

View file

@ -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
@ -829,6 +829,7 @@ public class ImportModule extends TestRunner {
}
}
@Test
public void testPackageImportDisambiguates(Path base) throws Exception {
Path current = base.resolve(".");
Path src = current.resolve("src");
@ -919,4 +920,50 @@ public class ImportModule extends TestRunner {
.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();
}
}

View file

@ -804,7 +804,7 @@ public class AnnotationsOnModules extends ModuleTestBase {
.writeAll()
.getOutputLines(OutputKind.DIRECT);
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"
);