Skip to content

Commit

Permalink
get/setEcho() -> echo()
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed May 21, 2024
1 parent c94b290 commit 5392455
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions test/jdk/java/io/Console/RestoreEchoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,11 @@ public static void main(String... args) throws Throwable {
throw new RuntimeException("Test failed. jdk.console is not java.base");
}

MethodHandle MH_getEcho = MethodHandles.privateLookupIn(JdkConsoleImpl.class, MethodHandles.lookup())
.findStatic(JdkConsoleImpl.class, "getEcho", MethodType.methodType(boolean.class));
MethodHandle MH_setEcho = MethodHandles.privateLookupIn(JdkConsoleImpl.class, MethodHandles.lookup())
.findStatic(JdkConsoleImpl.class, "setEcho", MethodType.methodType(void.class, boolean.class));
MethodHandle MH_echo = MethodHandles.privateLookupIn(JdkConsoleImpl.class, MethodHandles.lookup())
.findStatic(JdkConsoleImpl.class, "echo", MethodType.methodType(boolean.class, boolean.class));

var initialEcho = Boolean.parseBoolean(args[0]);
var originalEcho = (boolean)MH_getEcho.invokeExact();
MH_setEcho.invokeExact(initialEcho);
var originalEcho = (boolean)MH_echo.invokeExact(initialEcho);

Console con = System.console();
if (con == null) {
Expand All @@ -114,8 +111,7 @@ public static void main(String... args) throws Throwable {
input = String.valueOf(con.readPassword("password prompt: "));
con.printf("password is %s\n", input);

var echoAfter = (boolean)MH_getEcho.invokeExact();
MH_setEcho.invokeExact(originalEcho);
var echoAfter = (boolean)MH_echo.invokeExact(originalEcho);

var echoStates =
"""
Expand Down

0 comments on commit 5392455

Please sign in to comment.