# HG changeset patch # User shinyafox # Date 1475138182 -32400 # Node ID 8c2aab77c2d214e817e68f5239d470b83fb0478c # Parent 2a3e74c5ad8af832c584c22ed9575dd9c2a64124 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access Reviewed-by: rfield, jlahoda diff -r 2a3e74c5ad8a -r 8c2aab77c2d2 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);