Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8342936: Enhance java.io.IO with parameter-less println() and readln() #21693

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}
}

/**
16 changes: 16 additions & 0 deletions test/langtools/jdk/jshell/ConsoleTest.java
Original file line number Diff line number Diff line change
@@ -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!");
}