8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
Reviewed-by: rfield, jlahoda
--- 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);