From 9bcdfc428597e1465c8a014d816ef671420d22df Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Wed, 14 Dec 2022 11:36:04 +0000 Subject: [PATCH] 8298425: System.console().readLine() hangs in jshell Reviewed-by: naoto, alanb --- .../execution/JdiDefaultExecutionControl.java | 8 +++- test/langtools/jdk/jshell/ConsoleTest.java | 42 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/langtools/jdk/jshell/ConsoleTest.java diff --git a/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java b/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java index c9590380064..0044c1b4be4 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java @@ -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 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(); diff --git a/test/langtools/jdk/jshell/ConsoleTest.java b/test/langtools/jdk/jshell/ConsoleTest.java new file mode 100644 index 00000000000..5d2d8602df7 --- /dev/null +++ b/test/langtools/jdk/jshell/ConsoleTest.java @@ -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"); + } + +}