Console.readPassword() was failed on Linux s390x platform
Ichiroh Takiguchi
takiguc at linux.vnet.ibm.com
Thu Jul 19 18:06:06 UTC 2018
Hello.
I ran following testcase on Linux s390x platform.
------
import java.io.Console;
public class ConsoleTestC {
public static void main(String[] args) {
Console console = System.console();
char password[] = console.readPassword("password> ");
System.out.println(password);
}
}
------
Test instruction
1. Compile and run ConsoleTestC on terminal
$ java ConsoleTestC
password>
2. Type "abc", then "abc" is displayed
3. Type "ls", but nothing is displayed
4. Type "stty echo" to change back the setting
I wrote following program for PD.
------
import java.io.*;
import java.lang.reflect.*;
public class ConsoleTestB {
public static void main(String[] args) throws Exception {
Console console = System.console();
Method echo = Console.class.getDeclaredMethod("echo",
boolean.class);
echo.setAccessible(true);
System.out.println("echo false");
System.out.println(echo.invoke(console, false));
console.reader().read();
System.out.println("echo true");
System.out.println(echo.invoke(console, true));
}
}
------
Test instruction
1. Compile and run ConsoleTestB on terminal
$ java ConsoleTestB
......
echo false
false
2. Last output should be "true", so Java could not read echo flag
properly
3. Press return key
echo true
false
$
Console.readPassword() could not read initial echo flag,
so move back to "-echo" instead of "echo"
Fix candidate is as follows:
======
diff -r 14708e1acdc3 src/java.base/unix/native/libjava/Console_md.c
--- a/src/java.base/unix/native/libjava/Console_md.c Tue Jul 03
09:27:41 2018 +0800
+++ b/src/java.base/unix/native/libjava/Console_md.c Fri Jul 20
02:52:38 2018 +0900
@@ -56,7 +56,7 @@
JNU_ThrowIOExceptionWithLastError(env, "tcgetattr failed");
return !on;
}
- old = (tio.c_lflag & ECHO);
+ old = (tio.c_lflag & ECHO) == ECHO ? JNI_TRUE : JNI_FALSE;
if (on) {
tio.c_lflag |= ECHO;
} else {
======
I'd like to obtain a sponsor for this patch.
Could you put it into JDK11 ?
Thanks,
Ichiroh Takiguchi
IBM Japan, Ltd.
More information about the core-libs-dev
mailing list