possible problem with JNI GetStringUTFChars

Claes Redestad claes.redestad at oracle.com
Thu Jan 24 18:32:56 UTC 2019


Hi Alan,

GetStringUTFChars unfortunately doesn't give you true UTF-8, but a 
modified UTF-8 sequence
as used by the VM internally for historical reasons.

See answers to this related question on SO (which contains links to 
official docs):
https://stackoverflow.com/questions/32205446/getting-true-utf-8-characters-in-java-jni

HTH

/Claes

On 2019-01-24 19:23, Alan Snyder wrote:
> I am having a problem with file names that contain emojis when passed to a macOS system call.
>
> Things work when I convert the path to bytes in Java, but fail (file not found) when I convert the path to bytes in native code using GetStringUTFChars.
>
> For example, where String.getBytes() returns
>
> -16 -97 -115 -69
>
> GetStringUTFChars returns:
>
> -19 -96 -68 -19 -67 -69
>
> I’m not a UTF expert, so can someone say whether I should file a bug report?
>
> (Tested in JDK 9, 11, and a fairly recent 12)
>



More information about the core-libs-dev mailing list