mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-02 06:28:23 +00:00
8080843: JShell tool: invalid key error occurs when external editor is used
Reviewed-by: vromero
This commit is contained in:
parent
8d93dc2a15
commit
3bad85523c
@ -73,8 +73,8 @@ public class ExternalEditor {
|
||||
*/
|
||||
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 @@ public class ExternalEditor {
|
||||
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 @@ public class ExternalEditor {
|
||||
|
||||
boolean valid = key.reset();
|
||||
if (!valid) {
|
||||
errorHandler.accept("Invalid key");
|
||||
// The watch service has been closed, we are done
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 @@ public class ExternalEditorTest extends EditorTestBase {
|
||||
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())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user