8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
authorshinyafox
Thu, 29 Sep 2016 17:36:22 +0900
changeset 41249 8c2aab77c2d2
parent 41248 2a3e74c5ad8a
child 41250 0dea223af562
8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access Reviewed-by: rfield, jlahoda
langtools/test/jdk/jshell/HistoryTest.java
--- a/langtools/test/jdk/jshell/HistoryTest.java	Wed Sep 28 16:36:10 2016 +0900
+++ b/langtools/test/jdk/jshell/HistoryTest.java	Thu Sep 29 17:36:22 2016 +0900
@@ -23,6 +23,7 @@
 
 /*
  * @test
+ * @bug 8166744
  * @summary Test Completion
  * @modules jdk.internal.le/jdk.internal.jline.extra
  *          jdk.jshell/jdk.internal.jshell.tool
@@ -75,6 +76,44 @@
              });
     }
 
+    public void test8166744() {
+        test(
+             a -> {if (!a) setCommandInput("class C {\n");},
+             a -> {if (!a) setCommandInput("void f() {\n");},
+             a -> {if (!a) setCommandInput("}\n");},
+             a -> {assertCommand(a, "}", "|  created class C");},
+             a -> {
+                 if (!a) {
+                     try {
+                         previousAndAssert(getHistory(), "}");
+                         previousAndAssert(getHistory(), "}");
+                         previousAndAssert(getHistory(), "void f() {");
+                         previousAndAssert(getHistory(), "class C {");
+                         getHistory().add("class C{");
+                     } catch (Exception ex) {
+                         throw new IllegalStateException(ex);
+                     }
+                 }
+                 assertCommand(a, "int dummy;", "dummy ==> 0");
+             });
+        test(
+             a -> {if (!a) setCommandInput("class C {\n");},
+             a -> {if (!a) setCommandInput("void f() {\n");},
+             a -> {if (!a) setCommandInput("}\n");},
+             a -> {assertCommand(a, "}", "|  created class C");},
+             a -> {
+                 if (!a) {
+                     try {
+                         previousSnippetAndAssert(getHistory(), "class C {");
+                         getHistory().add("class C{");
+                     } catch (Exception ex) {
+                         throw new IllegalStateException(ex);
+                     }
+                 }
+                 assertCommand(a, "int dummy;", "dummy ==> 0");
+             });
+    }
+
     private EditingHistory getHistory() throws Exception {
         Field input = repl.getClass().getDeclaredField("input");
         input.setAccessible(true);