Skip to content

Commit

Permalink
8345248: Module name 'transitive' not accepted for requires transitive
Browse files Browse the repository at this point in the history
  • Loading branch information
lahodaj committed Nov 29, 2024
1 parent ece0401 commit 11932dc
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4208,16 +4208,16 @@ List<JCDirective> moduleDirectiveList() {
while (true) {
switch (token.kind) {
case IDENTIFIER:
if (token.name() == names.transitive && !isTransitive) {
if (token.name() == names.transitive) {
Token t1 = S.token(1);
if (t1.kind == SEMI || t1.kind == DOT) {
break loop;
}
if (isTransitive) {
log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.RepeatedModifier);
}
isTransitive = true;
break;
} else if (token.name() == names.transitive && isTransitive) {
log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.RepeatedModifier);
break;
} else {
break loop;
}
Expand Down
103 changes: 103 additions & 0 deletions test/langtools/tools/javac/modules/RequiresTransitiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/*
* @test
* @bug 8345248
* @summary tests for "requires transitive"
* @library /tools/lib
* @modules
Expand All @@ -34,6 +35,8 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

import toolbox.JavacTask;
import toolbox.Task;
Expand Down Expand Up @@ -256,4 +259,104 @@ public void testRepeatedModifiers(Path base) throws Exception {
throw new Exception("expected output not found: " + e);
}
}

@Test //JDK-8345248:
public void testTransitiveModuleName(Path base) throws Exception {
Path lib = base.resolve("lib");
Path libSrc = lib.resolve("src");
Path transitive = libSrc.resolve("transitive");
tb.writeJavaFiles(transitive,
"""
module transitive {
}
"""
);
Path transitiveA = libSrc.resolve("transitive.a");
tb.writeJavaFiles(transitiveA,
"""
module transitive.a {
}
"""
);

Path libClasses = lib.resolve("classes");
Files.createDirectories(libClasses);

new JavacTask(tb, Task.Mode.CMDLINE)
.options("--module-source-path", libSrc.toString())
.files(findJavaFiles(libSrc))
.outdir(libClasses)
.run()
.writeAll();

Path src = base.resolve("src");
Path classes = base.resolve("classes");

Files.createDirectories(classes);

tb.writeJavaFiles(src,
"""
module m {
requires transitive;
requires transitive.a;
}
"""
);

new JavacTask(tb, Task.Mode.CMDLINE)
.options("--module-path", libClasses.toString())
.sourcepath(src)
.files(findJavaFiles(src))
.outdir(classes)
.run()
.writeAll();

tb.writeJavaFiles(src,
"""
module m {
requires transitive transitive;
requires transitive transitive.a;
}
"""
);

new JavacTask(tb, Task.Mode.CMDLINE)
.options("--module-path", libClasses.toString())
.sourcepath(src)
.files(findJavaFiles(src))
.outdir(classes)
.run()
.writeAll();

tb.writeJavaFiles(src,
"""
module m {
requires transitive transitive transitive;
requires transitive transitive transitive.a;
}
"""
);

List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
.options("--module-path", libClasses.toString(),
"-XDrawDiagnostics")
.sourcepath(src)
.files(findJavaFiles(src))
.outdir(classes)
.run()
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);


List<String> expected = List.of(
"module-info.java:2:25: compiler.err.repeated.modifier",
"module-info.java:3:25: compiler.err.repeated.modifier",
"2 errors"
);

if (!Objects.equals(expected, log)) {
throw new Exception("expected: " + expected +
", but got: " + log);
}
}
}

0 comments on commit 11932dc

Please sign in to comment.