[aarch64-port-dev ] hotspot jtreg runtime/BoolReturn/JNIBooleanTest.java failure
Andrew Haley
aph at redhat.com
Fri Sep 21 13:55:22 UTC 2018
Here's the bug in Java's runtime which provoked this error:
JNIEXPORT jboolean JNICALL
Java_java_io_Console_echo(JNIEnv *env,
jclass cls,
jboolean on)
{
struct termios tio;
jboolean old;
int tty = fileno(stdin);
if (tcgetattr(tty, &tio) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "tcgetattr failed");
return !on;
}
old = (tio.c_lflag & ECHO);
if (on) {
tio.c_lflag |= ECHO;
} else {
tio.c_lflag &= ~ECHO;
}
if (tcsetattr(tty, TCSANOW, &tio) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "tcsetattr failed");
}
return old;
}
It's super-hard to see the bug because you could (and I did) naively
assume that jboolean behaves like boolean (or C++ bool) but it
doesn't. It should be:
old = (tio.c_lflag & ECHO) != 0;
which is why, I guess, the author wrapped the expression in
parentheses.
But note that if we simply fix this in HotSpot, it's only right by
accident: ECHO just happens to be 0000010, so we know the result of
(tio.c_lflag & ECHO) will fit in a jboolean, but that's just an
accident.
--
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the hotspot-dev
mailing list