8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
authorrfield
Fri, 16 Jun 2017 10:32:46 -0700
changeset 45602 7aeef976cb06
parent 45601 f0530afb3b91
child 45603 2161c0003389
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n> Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
langtools/test/jdk/jshell/ToolSimpleTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Fri Jun 16 04:54:37 2017 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Fri Jun 16 10:32:46 2017 -0700
@@ -1706,9 +1706,13 @@
         // Documentation pseudo-commands
         registerCommand(new Command("/<id>",
                 "help.id",
+                arg -> cmdHelp("rerun"),
+                EMPTY_COMPLETION_PROVIDER,
                 CommandKind.HELP_ONLY));
         registerCommand(new Command("/-<n>",
                 "help.previous",
+                arg -> cmdHelp("rerun"),
+                EMPTY_COMPLETION_PROVIDER,
                 CommandKind.HELP_ONLY));
         registerCommand(new Command("intro",
                 "help.intro",
--- a/langtools/test/jdk/jshell/ToolSimpleTest.java	Fri Jun 16 04:54:37 2017 +0000
+++ b/langtools/test/jdk/jshell/ToolSimpleTest.java	Fri Jun 16 10:32:46 2017 -0700
@@ -388,6 +388,14 @@
         );
     }
 
+    @Test
+    public void testConfusedUserPseudoCommands() {
+        test(
+                (a) -> assertHelp(a, "/-<n>", "last snippet", "digits"),
+                (a) -> assertHelp(a, "/<id>", "last snippet", "digits")
+        );
+    }
+
     private void assertHelp(boolean a, String command, String... find) {
         assertCommandCheckOutput(a, command, s -> {
             for (String f : find) {