Is returning a value != '0' or '1' as jboolean from a JNI function legal? (original) (raw)

Aleksey Shipilev shade at redhat.com
Fri Aug 17 17:25:49 UTC 2018


On 08/17/2018 05:12 PM, Volker Simonis wrote:

The offending code in Consolemd.c looks as follows:

#define ECHO 8 JNIEXPORT jboolean JNICALL JavajavaioConsoleecho(...) { jboolean old; ... old = (tio.clflag & ECHO); ... return old; } The intention of this code is to return "true" if the ECHO flag was set but it really returns the value of ECHO (which is defined as '8' in a system header). The question now is, if a Java SE compatible VM guarantees that any arbitrary, non-zero valued jboolean will be interpreted as "JNITRUE" and only a zero valued jboolean will be interpreted as "JNIFALSE"? Or, the other way round, is the normalization performed by the HotSpot result handlers necessary (i.e. enforced by the specification) or just a convenience to fix broken code like the above from Console.echo()?

I think this is intentional aftermath of boolean value normalization: https://bugs.openjdk.java.net/browse/JDK-8161720

So, Java_java_io_Console_echo looks broken and needs to be fixed, by e.g.:

Thanks, -Aleksey



More information about the core-libs-dev mailing list