On Wed, 18 Aug 2021 23:57:38 GMT, Phil Race <p...@openjdk.org> wrote:

> When Ctrl+Space is pressed mac generates a string that contains the single 
> unicode code point zero.
> The fn that converts it from an NSString to a Java String is using 
> NewStringUTF.
> The input to that is a null terminated string which also has zero as the code 
> point it contains, so
> we actually end up with a zero length Java string instead of the intended one 
> code point in length.
> So the fix is to change the way we convert the string.
> 
> There's an existing test CtrlAscii.java which sort of tests some of this but 
> it isn't asserting that you
> get what you expect, its mostly testing you don't get something *unexpected* 
> .. it will happily pass if
> you don't get keyevents. I did not want to change the purpose of that test 
> for this.
> So I wrote a test specific to this Ctrl+Space to verify the fix but also ran 
> all the standard automated tests too.

src/java.desktop/macosx/native/libosxapp/JNIUtilities.m line 55:

> 53:     jstring jStr = (*env)->NewString(env, buffer, len);
> 54:     free(buffer);
> 55:     CHECK_EXCEPTION();

Shouldn't it be better to call CHECK_EXCEPTION_NULL_RETURN() here to return 
null in case NewString throw exception in which case, I guess jStr will have 
garbage.

Also, it seems 
https://developer.apple.com/documentation/foundation/nsstring/1408720-getcharacters
 says the buffer must be large enough...aRange.length*sizeof(unichar) so 
shouldn't the NSRange be created for 
(0, len * sizeof(unichar))

-------------

PR: https://git.openjdk.java.net/jdk/pull/5177

Reply via email to