possible problem with JNI GetStringUTFChars
peter.levart at gmail.com
Thu Jan 31 07:28:06 UTC 2019
On 1/26/19 8:38 PM, Alan Snyder wrote:
> My usage of GetStringUTFChars was to pass a String as a parameter to a system call that takes a NUL-terminated UTF-8 string (a file path). Obviously, the system call does not accept strings containing NUL. I suspect this is a common case.
> Therefore, my needs would be met by a (new) primitive that returns UTF-8 and fails if the String contains NUL.
I had similar needs when interfacing a native library and resorted to
encoding the string in Java into a NUL terminated native ByteBuffer,
which I then used in JNI code to obtain a pointer to native memory
containing the encoded bytes. So I used ByteBuffer parameters in place
where Strings would be passed to native methods...
More information about the core-libs-dev