Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1071

JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0x80

$
0
0

JNI method NewStringUTF expects input as a modified UTF8 string, the difference between Standard UTF-8 and modified UTF-8 is in how it handles the null (U+0000) character. In standard UTF-8, the null character is encoded as a single byte (0x00). However, in Modified UTF-8, the null character is encoded using two bytes (0xC0 0x80). Link

but when I'm trying to pass a string ending with the null character encoded using two bytes 0xC0 0x80. I'm getting error in NewStringUTF method:enter image description here

Thus, It seems an extra <0x80> is getting added at the end and the method is not able to recognise last three characters.

However, When I'm passing a standard UTF8 encoded string i.e. a string ending with the null character as a single byte (0x00) to NewStringUTF method it is not giving any error. I'm not able to figure out reason behind this behaviour.

Moreover, the JNI method GetStringUTFChars is supposed to return a pointer to a modified UTF-8 string, but when I'm printing each character of returned string I'm again getting a string ending with the null character as a single byte (0x00), i.e. Standard UTF8 string.

Could someone explain why NewStringUTF method is not throwing any error when a Standard UTF8 string is passed as input however it's throwing error when I'm trying to pass a Modified UTF8 encoded string.

Also, why GetStringUTFChars method is return a Standard UTF8 string, when it's mentioned in the docs that it is supposed to return a Modified UTF8 string.


Viewing all articles
Browse latest Browse all 1071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>