8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
authorrfield
Thu, 02 Nov 2017 11:09:28 -0700
changeset 47517 b5ad886110b3
parent 47516 3ce28db4393e
child 47518 783d04ecccc3
8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions() Reviewed-by: jlahoda
src/jdk.jshell/share/classes/jdk/internal/jshell/debug/InternalDebugControl.java
src/jdk.jshell/share/classes/jdk/jshell/JShell.java
src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java
test/langtools/jdk/jshell/ToolTabSnippetTest.java
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/debug/InternalDebugControl.java	Thu Nov 02 11:03:45 2017 -0700
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/debug/InternalDebugControl.java	Thu Nov 02 11:09:28 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,11 +29,10 @@
 import jdk.jshell.JShell;
 
 /**
-/**
  * This class is used to externally control output messages for debugging the
  * implementation of the JShell API.
  * <p>
- * This is not part of the SPI, not API.
+ * This is not part of the SPI nor API.
  */
 public class InternalDebugControl {
 
@@ -141,7 +140,7 @@
      * @param ex the fatal Exception
      * @param where additional context
      */
-    public static void debug(JShell state, PrintStream err, Exception ex, String where) {
+    public static void debug(JShell state, PrintStream err, Throwable ex, String where) {
         if (isDebugEnabled(state, 0xFFFFFFFF)) {
             err.printf("Fatal error: %s: %s\n", where, ex.getMessage());
             ex.printStackTrace(err);
--- a/src/jdk.jshell/share/classes/jdk/jshell/JShell.java	Thu Nov 02 11:03:45 2017 -0700
+++ b/src/jdk.jshell/share/classes/jdk/jshell/JShell.java	Thu Nov 02 11:09:28 2017 -0700
@@ -807,7 +807,7 @@
         InternalDebugControl.debug(this, err, flags, format, args);
     }
 
-    void debug(Exception ex, String where) {
+    void debug(Throwable ex, String where) {
         InternalDebugControl.debug(this, err, ex, where);
     }
 
--- a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Thu Nov 02 11:03:45 2017 -0700
+++ b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Thu Nov 02 11:09:28 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,7 +58,6 @@
 import com.sun.tools.javac.util.Pair;
 import jdk.jshell.CompletenessAnalyzer.CaInfo;
 import jdk.jshell.TaskFactory.AnalyzeTask;
-import jdk.jshell.TaskFactory.ParseTask;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -255,6 +254,9 @@
         suspendIndexing();
         try {
             return completionSuggestionsImpl(code, cursor, anchor);
+        } catch (Throwable exc) {
+            proc.debug(exc, "Exception thrown in SourceCodeAnalysisImpl.completionSuggestions");
+            return Collections.emptyList();
         } finally {
             resumeIndexing();
         }
@@ -1148,6 +1150,9 @@
         suspendIndexing();
         try {
             return documentationImpl(code, cursor, computeJavadoc);
+        } catch (Throwable exc) {
+            proc.debug(exc, "Exception thrown in SourceCodeAnalysisImpl.documentation");
+            return Collections.emptyList();
         } finally {
             resumeIndexing();
         }
--- a/test/langtools/jdk/jshell/ToolTabSnippetTest.java	Thu Nov 02 11:03:45 2017 -0700
+++ b/test/langtools/jdk/jshell/ToolTabSnippetTest.java	Thu Nov 02 11:09:28 2017 -0700
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 8177076 8185426
+ * @bug 8177076 8185426 8188072
  * @modules
  *     jdk.compiler/com.sun.tools.javac.api
  *     jdk.compiler/com.sun.tools.javac.main
@@ -191,6 +191,10 @@
             //no crash:
             inputSink.write("\u0003new Stringbuil\011");
             waitOutput(out, "\u0005new Stringbuil\u0007");
+
+            //no crash: 8188072
+            inputSink.write("\u0003for (int:\011");
+            waitOutput(out, "\u0005for \\(int:\u0007");
         });
     }