# HG changeset patch # User rfield # Date 1488567488 28800 # Node ID d9ddf704d193c35e7718b1b434e7a9262c14ac97 # Parent f420de7e26fa9f2648b68888860da89bc9ed3006 8175886: JShell: crash on tab-complete with NPE. Reviewed-by: jlahoda diff -r f420de7e26fa -r d9ddf704d193 langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.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: { diff -r f420de7e26fa -r d9ddf704d193 langtools/test/jdk/jshell/CompletionSuggestionTest.java --- 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");