jboolean handling in native JDK code - was : RE: 8211163: UNIX version of Java_java_io_Console_echo does not return a clean boolean

Baesken, Matthias matthias.baesken at sap.com
Fri Sep 28 12:32:49 UTC 2018


Hi Andrew,  maybe  this  is  another "bad" jboolean handling :


src/java.desktop/windows/native/libawt/windows/awt_List.cpp

1004JNIEXPORT jboolean JNICALL
1005Java_sun_awt_windows_WListPeer_isSelected(JNIEnv *env, jobject self,
1006                                          jint index)
1007{
1008    TRY;
1009
1010    SelectElementStruct *ses = new SelectElementStruct;
1011    ses->list = env->NewGlobalRef(self);
1012    ses->index = index;
1013
1014    return (jboolean)((intptr_t)AwtToolkit::GetInstance().SyncCall(
1015        (void *(*)(void *))AwtList::_IsSelected, ses));


Shouldn't we better compare  the  pointer to NULL   instead of just  casting ?

Best regards, Matthias


> -----Original Message-----
> From: jdk-dev <jdk-dev-bounces at openjdk.java.net> On Behalf Of Andrew
> Haley
> Sent: Mittwoch, 26. September 2018 17:52
> To: jdk-dev at openjdk.java.net
> Subject: RFR: 8211163: UNIX version of Java_java_io_Console_echo does not
> return a clean boolean
> 
> Java_java_io_Console_echo looks like this:
> 
> JNIEXPORT jboolean JNICALL
> Java_java_io_Console_echo(JNIEnv *env, jclass cls, jboolean on)
> {
>     DWORD fdwMode;
>     jboolean old;
>     ...
>     old = (fdwMode & ENABLE_ECHO_INPUT);
>     ...
>     return old;
> }
> 
> It only works by accident. jboolean is an unsigned byte.
> ENABLE_ECHO_INPUT on the systems I know of is 0000010, so fdwMode &
> ENABLE_ECHO_INPUT fits into the result, but only by accident. We
> should do things properly and return a clean boolean.
> 
> Note that the Windows version of the code is correct: I assume the
> UNIX version is an oversight.
> 
> https://bugs.openjdk.java.net/browse/JDK-8211163
> http://cr.openjdk.java.net/~aph/8211163/
> 
> OK?
> 
> --
> 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 jdk-dev mailing list