mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8172668: NPE in jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.importNamed(
Guarding against noType returned from ErrorType.getOriginalType. Reviewed-by: mcimadamore
This commit is contained in:
parent
96c8382650
commit
abddf32a62
2 changed files with 84 additions and 1 deletions
|
@ -410,7 +410,9 @@ public class TypeEnter implements Completer {
|
||||||
importNamedStatic(tree, p, name, localEnv);
|
importNamedStatic(tree, p, name, localEnv);
|
||||||
chk.checkCanonical(imp.selected);
|
chk.checkCanonical(imp.selected);
|
||||||
} else {
|
} else {
|
||||||
TypeSymbol c = attribImportType(imp, localEnv).getOriginalType().tsym;
|
Type importedType = attribImportType(imp, localEnv);
|
||||||
|
Type originalType = importedType.getOriginalType();
|
||||||
|
TypeSymbol c = originalType.hasTag(CLASS) ? originalType.tsym : importedType.tsym;
|
||||||
chk.checkCanonical(imp);
|
chk.checkCanonical(imp);
|
||||||
importNamed(tree.pos(), c, env, tree);
|
importNamed(tree.pos(), c, env, tree);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
|
* @bug 8169197 8172668
|
||||||
* @summary Check convenient errors are produced for inaccessible classes.
|
* @summary Check convenient errors are produced for inaccessible classes.
|
||||||
* @library /tools/lib
|
* @library /tools/lib
|
||||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
|
@ -512,4 +513,84 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase {
|
||||||
.writeAll();
|
.writeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnresolvableInImport(Path base) throws Exception {
|
||||||
|
Path src = base.resolve("src");
|
||||||
|
Path src_m1 = src.resolve("m1x");
|
||||||
|
tb.writeJavaFiles(src_m1,
|
||||||
|
"module m1x { }",
|
||||||
|
"package api; import can.not.resolve; public class Api { }");
|
||||||
|
Path classes = base.resolve("classes");
|
||||||
|
tb.createDirectories(classes);
|
||||||
|
|
||||||
|
List<String> log = new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics",
|
||||||
|
"--module-source-path", src.toString())
|
||||||
|
.outdir(classes)
|
||||||
|
.files(findJavaFiles(src))
|
||||||
|
.run(Task.Expect.FAIL)
|
||||||
|
.writeAll()
|
||||||
|
.getOutputLines(Task.OutputKind.DIRECT);
|
||||||
|
|
||||||
|
List<String> expected = Arrays.asList(
|
||||||
|
"Api.java:1:28: compiler.err.doesnt.exist: can.not",
|
||||||
|
"1 error");
|
||||||
|
|
||||||
|
if (!expected.equals(log))
|
||||||
|
throw new Exception("expected output not found; actual: " + log);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMissingKnownClass(Path base) throws Exception {
|
||||||
|
Path src = base.resolve("src");
|
||||||
|
Path src_m1 = src.resolve("m1x");
|
||||||
|
tb.writeJavaFiles(src_m1,
|
||||||
|
"module m1x { exports api; }",
|
||||||
|
"package api; public class Base { }",
|
||||||
|
"package api; public class Sub extends Base { }");
|
||||||
|
Path classes = base.resolve("classes");
|
||||||
|
tb.createDirectories(classes);
|
||||||
|
Path m1xClasses = classes.resolve("m1x");
|
||||||
|
tb.createDirectories(m1xClasses);
|
||||||
|
|
||||||
|
new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics")
|
||||||
|
.outdir(m1xClasses)
|
||||||
|
.files(findJavaFiles(src_m1))
|
||||||
|
.run(Task.Expect.SUCCESS)
|
||||||
|
.writeAll();
|
||||||
|
|
||||||
|
Files.delete(m1xClasses.resolve("api").resolve("Base.class"));
|
||||||
|
|
||||||
|
Path src_m2 = src.resolve("m2x");
|
||||||
|
tb.writeJavaFiles(src_m2,
|
||||||
|
"module m2x { requires m1x; }",
|
||||||
|
"package test;\n" +
|
||||||
|
"import api.Sub;\n" +
|
||||||
|
"import api.Base;\n" +
|
||||||
|
"public class Test {\n" +
|
||||||
|
" Sub a2;\n" +
|
||||||
|
" Base a;\n" +
|
||||||
|
"}\n");
|
||||||
|
Path m2xClasses = classes.resolve("m2x");
|
||||||
|
tb.createDirectories(m2xClasses);
|
||||||
|
List<String> log = new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics",
|
||||||
|
"--module-path", classes.toString(),
|
||||||
|
"-XDdev")
|
||||||
|
.outdir(m2xClasses)
|
||||||
|
.files(findJavaFiles(src_m2))
|
||||||
|
.run(Task.Expect.FAIL)
|
||||||
|
.writeAll()
|
||||||
|
.getOutputLines(Task.OutputKind.DIRECT);
|
||||||
|
|
||||||
|
List<String> expected = Arrays.asList(
|
||||||
|
"Test.java:3:11: compiler.err.cant.resolve.location: kindname.class, Base, , , (compiler.misc.location: kindname.package, api, null)",
|
||||||
|
"Test.java:6:5: compiler.err.cant.resolve.location: kindname.class, Base, , , (compiler.misc.location: kindname.class, test.Test, null)",
|
||||||
|
"2 errors");
|
||||||
|
|
||||||
|
if (!expected.equals(log))
|
||||||
|
throw new Exception("expected output not found; actual: " + log);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue