Skip to content

Commit

Permalink
8344647: Make java.se participate in the preview language feature `re…
Browse files Browse the repository at this point in the history
…quires transitive java.base`

Reviewed-by: liach, vromero
Backport-of: d50b725
  • Loading branch information
lahodaj committed Dec 18, 2024
1 parent f703b6e commit 2cc14fa
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/java.base/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/java.se/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* questions.
*/

import jdk.internal.javac.ParticipatesInPreview;

/**
* Defines the API of the Java SE Platform.
*
Expand All @@ -40,7 +38,6 @@
* @moduleGraph
* @since 9
*/
@ParticipatesInPreview
module java.se {
requires transitive java.base;
requires transitive java.compiler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static int value(Set<RequiresFlag> s) {

@Override
public String toString() {
return String.format("ACC_%s (0x%04x", name(), value);
return String.format("ACC_%s (0x%04x)", name(), value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
51 changes: 49 additions & 2 deletions test/langtools/tools/javac/ImportModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -829,6 +829,7 @@ public class Test {
}
}

@Test
public void testPackageImportDisambiguates(Path base) throws Exception {
Path current = base.resolve(".");
Path src = current.resolve("src");
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ public class C {}
.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"
);

Expand Down

0 comments on commit 2cc14fa

Please sign in to comment.