8221759: Crash when completing \"java.io.File.path\"

Do not provide documentation for inaccessible elements.

Reviewed-by: rfield
This commit is contained in:
Jan Lahoda 2019-05-09 11:58:26 +02:00
parent d2472e6dcd
commit 55e1da1813
3 changed files with 26 additions and 2 deletions

View File

@ -1229,6 +1229,13 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
return Collections.emptyList();
}
Predicate<Element> accessibility = createAccessibilityFilter(at, tp);
if (!accessibility.test(el)) {
//not accessible
return Collections.emptyList();
}
elements = Stream.of(el);
} else {
return Collections.emptyList();

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439
* @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439 8221759
* @summary Test Completion and Documentation
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@ -325,6 +325,14 @@ public class CompletionSuggestionTest extends KullaTesting {
assertSignature("\"\".getBytes(\"\" |", "void String.getBytes(int, int, byte[], int)",
"byte[] String.getBytes(String) throws java.io.UnsupportedEncodingException",
"byte[] String.getBytes(java.nio.charset.Charset)");
//JDK-8221759:
Compiler compiler = new Compiler();
Path testOutDir = Paths.get("WithPrivateField");
String input = "package field; public class FieldTest { private static String field; private static String field2; }";
compiler.compile(testOutDir, input);
addToClasspath(compiler.getPath(testOutDir));
assertSignature("field.FieldTest.field|");
assertSignature("field.FieldTest.field2|");
}
public void testMethodsWithNoArguments() throws Exception {

View File

@ -23,7 +23,7 @@
/**
* @test
* @bug 8177076 8185426 8189595 8188072
* @bug 8177076 8185426 8189595 8188072 8221759
* @modules
* jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@ -266,6 +266,15 @@ public class ToolTabSnippetTest extends UITesting {
});
}
public void testCrash8221759() throws Exception {
doRunTest((inputSink, out) -> {
inputSink.write("java.io.File.path" + TAB);
waitOutput(out, "java.io.File.path\n" +
"pathSeparator pathSeparatorChar " +
REDRAW_PROMPT + "java.io.File.pathSeparator");
});
}
private Path prepareZip() {
String clazz1 =
"package jshelltest;\n" +