8298425: System.console().readLine() hangs in jshell

Reviewed-by: naoto, alanb
This commit is contained in:
Jan Lahoda 2022-12-14 11:36:04 +00:00
parent 27d4971182
commit 9bcdfc4285
2 changed files with 49 additions and 1 deletions
src/jdk.jshell/share/classes/jdk/jshell/execution
test/langtools/jdk/jshell

@ -48,6 +48,7 @@ import com.sun.jdi.StackFrame;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.VMDisconnectedException;
import com.sun.jdi.VirtualMachine;
import java.util.stream.Stream;
import jdk.jshell.spi.ExecutionControl;
import jdk.jshell.spi.ExecutionEnv;
import static jdk.jshell.execution.Util.remoteInputOutput;
@ -96,10 +97,15 @@ public class JdiDefaultExecutionControl extends JdiExecutionControl {
// timeout on I/O-socket
listener.setSoTimeout(timeout);
int port = listener.getLocalPort();
List<String> augmentedremoteVMOptions =
Stream.concat(env.extraRemoteVMOptions().stream(),
//disable System.console():
List.of("-Djdk.console=java.base").stream())
.toList();
// Set-up the JDI connection
JdiInitiator jdii = new JdiInitiator(port,
env.extraRemoteVMOptions(), remoteAgent, isLaunch, host,
augmentedremoteVMOptions, remoteAgent, isLaunch, host,
timeout, Collections.emptyMap());
VirtualMachine vm = jdii.vm();
Process process = jdii.process();

@ -0,0 +1,42 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8298425
* @summary Verify behavior of System.console()
* @build KullaTesting TestingInputStream
* @run testng ConsoleTest
*/
import org.testng.annotations.Test;
public class ConsoleTest extends KullaTesting {
@Test
public void testConsole1() {
assertEval("System.console()", "null");
}
}