diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java index da62a4a4fd3af..11de96b7fc339 100644 --- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java +++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java @@ -231,12 +231,7 @@ public String readln(String prompt) { @Override public String readln() { - try { - initJLineIfNeeded(); - return jline.readLine(); - } catch (EndOfFileException eofe) { - return null; - } + return readLine(); } @Override @@ -257,7 +252,12 @@ public String readLine(Locale locale, String format, Object ... args) { @Override public String readLine() { - return readLine(Locale.getDefault(Locale.Category.FORMAT), ""); + try { + initJLineIfNeeded(); + return jline.readLine(); + } catch (EndOfFileException eofe) { + return null; + } } @Override diff --git a/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java b/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java index e5935b8ef68ca..876f61ec85675 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java @@ -240,15 +240,7 @@ public String readln(String prompt) { */ @Override public String readln() { - try { - return sendAndReceive(() -> { - remoteInput.write(Task.READ_LINE_NO_PROMPT.ordinal()); - char[] line = readChars(); - return new String(line); - }); - } catch (IOException ex) { - throw new IOError(ex); - } + return readLine(); } /** @@ -287,7 +279,15 @@ public String readLine(Locale locale, String format, Object... args) { */ @Override public String readLine() { - return readLine(Locale.getDefault(Locale.Category.FORMAT), ""); + try { + return sendAndReceive(() -> { + remoteInput.write(Task.READ_LINE_NO_PROMPT.ordinal()); + char[] line = readChars(); + return new String(line); + }); + } catch (IOException ex) { + throw new IOError(ex); + } } /** diff --git a/test/langtools/jdk/jshell/ConsoleTest.java b/test/langtools/jdk/jshell/ConsoleTest.java index 29961a180bab6..4aedc0619397f 100644 --- a/test/langtools/jdk/jshell/ConsoleTest.java +++ b/test/langtools/jdk/jshell/ConsoleTest.java @@ -25,6 +25,7 @@ * @test * @bug 8298425 * @summary Verify behavior of System.console() + * @enablePreview * @build KullaTesting TestingInputStream * @run testng ConsoleTest */ @@ -67,6 +68,13 @@ public String readLine(String prompt) throws IOError { } }; assertEval("System.console().readLine(\"expected\")", "\"AB\""); + console = new ThrowingJShellConsole() { + @Override + public String readLine() throws IOError { + return "AB"; + } + }; + assertEval("System.console().readLine()", "\"AB\""); console = new ThrowingJShellConsole() { @Override public char[] readPassword(String prompt) throws IOError { @@ -210,6 +218,10 @@ public String readLine(String prompt) throws IOError { return console.readLine(prompt); } @Override + public String readLine() throws IOError { + return console.readLine(); + } + @Override public char[] readPassword(String prompt) throws IOError { return console.readPassword(prompt); } @@ -240,6 +252,10 @@ public String readLine(String prompt) throws IOError { throw new IllegalStateException("Not expected!"); } @Override + public String readLine() throws IOError { + throw new IllegalStateException("Not expected!"); + } + @Override public char[] readPassword(String prompt) throws IOError { throw new IllegalStateException("Not expected!"); }