8175886: JShell: crash on tab-complete with NPE.
authorrfield
Fri, 03 Mar 2017 10:58:08 -0800
changeset 44061 d9ddf704d193
parent 44060 f420de7e26fa
child 44062 9a579f258574
8175886: JShell: crash on tab-complete with NPE. Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java
langtools/test/jdk/jshell/CompletionSuggestionTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Fri Mar 03 09:58:11 2017 -0800
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Fri Mar 03 10:58:08 2017 -0800
@@ -381,7 +381,18 @@
                     }
                     ImportTree it = findImport(tp);
                     if (it != null) {
-                        addElements(membersOf(at, at.getElements().getPackageElement("").asType(), false), it.isStatic() ? STATIC_ONLY.and(accessibility) : accessibility, smartFilter, result);
+                        // the context of the identifier is an import, look for
+                        // package names that start with the identifier.
+                        // If and when Java allows imports from the default
+                        // package to the the default package which would allow
+                        // JShell to change to use the default package, and that
+                        // change is done, then this should use some variation
+                        // of membersOf(at, at.getElements().getPackageElement("").asType(), false)
+                        addElements(listPackages(at, ""),
+                                it.isStatic()
+                                        ? STATIC_ONLY.and(accessibility)
+                                        : accessibility,
+                                smartFilter, result);
                     }
                     break;
                 case CLASS: {
--- a/langtools/test/jdk/jshell/CompletionSuggestionTest.java	Fri Mar 03 09:58:11 2017 -0800
+++ b/langtools/test/jdk/jshell/CompletionSuggestionTest.java	Fri Mar 03 10:58:08 2017 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8131025 8141092 8153761 8145263 8131019
+ * @bug 8131025 8141092 8153761 8145263 8131019 8175886
  * @summary Test Completion and Documentation
  * @library /tools/lib
  * @modules jdk.compiler/com.sun.tools.javac.api
@@ -295,6 +295,11 @@
                 new HashSet<>(Arrays.asList("class")));
     }
 
+    public void testImportStart() {
+        assertCompletion("import ja|", "java", "javax");
+        assertCompletion("import o|", "org");
+    }
+
     public void testBrokenClassFile() throws Exception {
         Compiler compiler = new Compiler();
         Path testOutDir = Paths.get("CompletionTestBrokenClassFile");