mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8158123: NPE when the annotations is used in export-to of module-info
Reviewed-by: mcimadamore
This commit is contained in:
parent
294b2a0ec9
commit
e4edbb4617
2 changed files with 51 additions and 7 deletions
|
@ -3216,7 +3216,7 @@ public class JavacParser implements Parser {
|
||||||
List<JCExpression> moduleNames = null;
|
List<JCExpression> moduleNames = null;
|
||||||
if (token.kind == IDENTIFIER && token.name() == names.to) {
|
if (token.kind == IDENTIFIER && token.name() == names.to) {
|
||||||
nextToken();
|
nextToken();
|
||||||
moduleNames = qualidentList();
|
moduleNames = qualidentList(false);
|
||||||
}
|
}
|
||||||
accept(SEMI);
|
accept(SEMI);
|
||||||
defs.append(toP(F.at(pos).Exports(pkgName, moduleNames)));
|
defs.append(toP(F.at(pos).Exports(pkgName, moduleNames)));
|
||||||
|
@ -3635,7 +3635,7 @@ public class JavacParser implements Parser {
|
||||||
List<JCExpression> thrown = List.nil();
|
List<JCExpression> thrown = List.nil();
|
||||||
if (token.kind == THROWS) {
|
if (token.kind == THROWS) {
|
||||||
nextToken();
|
nextToken();
|
||||||
thrown = qualidentList();
|
thrown = qualidentList(true);
|
||||||
}
|
}
|
||||||
JCBlock body = null;
|
JCBlock body = null;
|
||||||
JCExpression defaultValue;
|
JCExpression defaultValue;
|
||||||
|
@ -3672,11 +3672,11 @@ public class JavacParser implements Parser {
|
||||||
|
|
||||||
/** QualidentList = [Annotations] Qualident {"," [Annotations] Qualident}
|
/** QualidentList = [Annotations] Qualident {"," [Annotations] Qualident}
|
||||||
*/
|
*/
|
||||||
List<JCExpression> qualidentList() {
|
List<JCExpression> qualidentList(boolean allowAnnos) {
|
||||||
ListBuffer<JCExpression> ts = new ListBuffer<>();
|
ListBuffer<JCExpression> ts = new ListBuffer<>();
|
||||||
|
|
||||||
List<JCAnnotation> typeAnnos = typeAnnotationsOpt();
|
List<JCAnnotation> typeAnnos = allowAnnos ? typeAnnotationsOpt() : List.nil();
|
||||||
JCExpression qi = qualident(true);
|
JCExpression qi = qualident(allowAnnos);
|
||||||
if (!typeAnnos.isEmpty()) {
|
if (!typeAnnos.isEmpty()) {
|
||||||
JCExpression at = insertAnnotationsToMostInner(qi, typeAnnos, false);
|
JCExpression at = insertAnnotationsToMostInner(qi, typeAnnos, false);
|
||||||
ts.append(at);
|
ts.append(at);
|
||||||
|
@ -3686,8 +3686,8 @@ public class JavacParser implements Parser {
|
||||||
while (token.kind == COMMA) {
|
while (token.kind == COMMA) {
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
typeAnnos = typeAnnotationsOpt();
|
typeAnnos = allowAnnos ? typeAnnotationsOpt() : List.nil();
|
||||||
qi = qualident(true);
|
qi = qualident(allowAnnos);
|
||||||
if (!typeAnnos.isEmpty()) {
|
if (!typeAnnos.isEmpty()) {
|
||||||
JCExpression at = insertAnnotationsToMostInner(qi, typeAnnos, false);
|
JCExpression at = insertAnnotationsToMostInner(qi, typeAnnos, false);
|
||||||
ts.append(at);
|
ts.append(at);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
|
* @bug 8158123
|
||||||
* @summary tests for module declarations
|
* @summary tests for module declarations
|
||||||
* @library /tools/lib
|
* @library /tools/lib
|
||||||
* @modules
|
* @modules
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import toolbox.JavacTask;
|
import toolbox.JavacTask;
|
||||||
import toolbox.Task;
|
import toolbox.Task;
|
||||||
|
@ -323,4 +325,46 @@ public class ModuleInfoTest extends ModuleTestBase {
|
||||||
if (!log.contains("module-info.java:1:30: compiler.err.duplicate.exports: m1"))
|
if (!log.contains("module-info.java:1:30: compiler.err.duplicate.exports: m1"))
|
||||||
throw new Exception("expected output not found");
|
throw new Exception("expected output not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify that annotations are not permitted at
|
||||||
|
* any of the module names or the package names.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testAnnotations(Path base) throws Exception {
|
||||||
|
Path src = base.resolve("src");
|
||||||
|
Path src_m1 = src.resolve("m1.sub");
|
||||||
|
Path classes = base.resolve("classes");
|
||||||
|
Files.createDirectories(classes);
|
||||||
|
|
||||||
|
String code = "module @m1.@sub { " +
|
||||||
|
"requires @p1.@p2; " +
|
||||||
|
"exports @p1.@p2; " +
|
||||||
|
"exports @p1.@p2 to @m2.@sub; " +
|
||||||
|
"exports @p1.@p2 to @m2.@sub, @m3.@sub; " +
|
||||||
|
"uses @p1.@Interface; " +
|
||||||
|
"provides @p1.@Interface with @p2.@Concrete; " +
|
||||||
|
"}";
|
||||||
|
String[] splittedCode = code.split("@");
|
||||||
|
int length = splittedCode.length;
|
||||||
|
String anno = "@Anno ";
|
||||||
|
|
||||||
|
for (int i = 1; i < length; i++) {
|
||||||
|
String preAnno = String.join("", Arrays.copyOfRange(splittedCode, 0, i));
|
||||||
|
String postAnno = String.join("", Arrays.copyOfRange(splittedCode, i, length));
|
||||||
|
String moduleInfo = preAnno + anno + postAnno;
|
||||||
|
tb.writeFile(src_m1.resolve("module-info.java"), moduleInfo);
|
||||||
|
|
||||||
|
String log = new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
|
||||||
|
.outdir(classes)
|
||||||
|
.files(findJavaFiles(src))
|
||||||
|
.run(Task.Expect.FAIL)
|
||||||
|
.writeAll()
|
||||||
|
.getOutput(Task.OutputKind.DIRECT);
|
||||||
|
|
||||||
|
if (!log.matches("(?s)^module\\-info\\.java:\\d+:\\d+: compiler\\.err\\.expected: token\\.identifier.*"))
|
||||||
|
throw new Exception("expected output not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue