8080843: JShell tool: invalid key error occurs when external editor is used
authorrfield
Tue, 31 May 2016 14:02:52 -0700
changeset 38828 520da69917b5
parent 38827 884d32899770
child 38829 f030290426ab
8080843: JShell tool: invalid key error occurs when external editor is used Reviewed-by: vromero
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ExternalEditor.java
langtools/test/jdk/jshell/ExternalEditorTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ExternalEditor.java	Tue May 31 13:00:17 2016 -0400
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ExternalEditor.java	Tue May 31 14:02:52 2016 -0700
@@ -73,8 +73,8 @@
      */
     private void setupWatch(String initialText) throws IOException {
         this.watcher = FileSystems.getDefault().newWatchService();
-        this.dir = Files.createTempDirectory("REPL");
-        this.tmpfile = Files.createTempFile(dir, null, ".repl");
+        this.dir = Files.createTempDirectory("jshelltemp");
+        this.tmpfile = Files.createTempFile(dir, null, ".edit");
         Files.write(tmpfile, initialText.getBytes(Charset.forName("UTF-8")));
         dir.register(watcher,
                 ENTRY_CREATE,
@@ -86,12 +86,17 @@
                 try {
                     key = watcher.take();
                 } catch (ClosedWatchServiceException ex) {
+                    // The watch service has been closed, we are done
                     break;
                 } catch (InterruptedException ex) {
-                    continue; // tolerate an intrupt
+                    // tolerate an interrupt
+                    continue;
                 }
 
                 if (!key.pollEvents().isEmpty()) {
+                    // Changes have occurred in temp edit directory,
+                    // transfer the new sources to JShell (unless the editor is
+                    // running directly in JShell's window -- don't make a mess)
                     if (!input.terminalEditorRunning()) {
                         saveFile();
                     }
@@ -99,7 +104,7 @@
 
                 boolean valid = key.reset();
                 if (!valid) {
-                    errorHandler.accept("Invalid key");
+                    // The watch service has been closed, we are done
                     break;
                 }
             }
--- a/langtools/test/jdk/jshell/ExternalEditorTest.java	Tue May 31 13:00:17 2016 -0400
+++ b/langtools/test/jdk/jshell/ExternalEditorTest.java	Tue May 31 14:02:52 2016 -0700
@@ -24,8 +24,7 @@
 /*
  * @test
  * @summary Testing external editor.
- * @bug 8080843 8143955
- * @ignore 8080843
+ * @bug 8143955 8080843
  * @modules jdk.jshell/jdk.internal.jshell.tool
  * @build ReplToolTesting CustomEditor EditorTestBase
  * @run testng ExternalEditorTest
@@ -197,22 +196,22 @@
                 a -> assertCommand(a, "/set editor", "|  The '/set editor' command requires a path argument"),
                 a -> assertCommand(a, "/set editor UNKNOWN", "|  Editor set to: UNKNOWN"),
                 a -> assertCommand(a, "int a;", null),
-                a -> assertCommand(a, "/ed 1",
-                        "|  Edit Error: process IO failure: Cannot run program \"UNKNOWN\": error=2, No such file or directory")
+                a -> assertCommandOutputStartsWith(a, "/ed 1",
+                        "|  Edit Error:")
         );
     }
 
-    @Test(enabled = false)
+    @Test
     public void testRemoveTempFile() {
         test(new String[]{"-nostartup"},
                 a -> assertCommandCheckOutput(a, "/set editor " + executionScript,
                         assertStartsWith("|  Editor set to: " + executionScript)),
                 a -> assertVariable(a, "int", "a", "0", "0"),
-                a -> assertEditOutput(a, "/e 1", assertStartsWith("|  Edit Error: Failure read edit file:"), () -> {
+                a -> assertEditOutput(a, "/ed 1", assertStartsWith("|  Edit Error: Failure in read edit file:"), () -> {
                     sendCode(CustomEditor.REMOVE_CODE);
                     exit();
                 }),
-                a -> assertCommandCheckOutput(a, "/v", assertVariables())
+                a -> assertCommandCheckOutput(a, "/vars", assertVariables())
         );
     }