8221759: Crash when completing \"java.io.File.path\"
authorjlahoda
Thu, 09 May 2019 11:58:26 +0200
changeset 54778 d1d6e939803f
parent 54777 206afa6372ae
child 54779 e0bd4c7a176e
8221759: Crash when completing \"java.io.File.path\" Summary: Do not provide documentation for inaccessible elements. Reviewed-by: rfield
src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java
test/langtools/jdk/jshell/CompletionSuggestionTest.java
test/langtools/jdk/jshell/ToolTabSnippetTest.java
--- a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Wed May 08 09:50:23 2019 +0000
+++ b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Thu May 09 11:58:26 2019 +0200
@@ -1229,6 +1229,13 @@
                     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();
--- a/test/langtools/jdk/jshell/CompletionSuggestionTest.java	Wed May 08 09:50:23 2019 +0000
+++ b/test/langtools/jdk/jshell/CompletionSuggestionTest.java	Thu May 09 11:58:26 2019 +0200
@@ -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 @@
         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 {
--- a/test/langtools/jdk/jshell/ToolTabSnippetTest.java	Wed May 08 09:50:23 2019 +0000
+++ b/test/langtools/jdk/jshell/ToolTabSnippetTest.java	Thu May 09 11:58:26 2019 +0200
@@ -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 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" +