Make JNI string conversions behave like ObjC string conversions - #174
Make JNI string conversions behave like ObjC string conversions#174jb-gcx wants to merge 1 commit into
Conversation
Return empty string if conversion fails
|
Hi @jb-gcx, Thanks for the contribution! This is an area I had hesitated for a long time. On one hand, I kind of want to make programming errors stand out more so that they could be corrected earlier. Passing invalid characters as string is one of them, binary objects should be passed using the On the other hand, I understand it could be annoying when simply passing a string argument may require the caller to handle potential encoding errors. I can't decided which is better, convenience or strictness. Also, if you just want to return a fallback string when there is an encoding error, |
|
Thanks for the response @lifengsc ! Regarding your worries about errors slipping past, I absolutely agree. I much prefer them to be visible in general. The reason I feel confident about this change is that iOS already behaves this way. There are arguments for either style of dealing with errors, but I think the most important thing is to use the same style between platforms. To be consistent, the options are:
Lastly, about the |
When a C++ std::string contains invalid UTF-8, the result is an empty string when trying to pass it to ObjC. For JNI, it caused an exception. For consistency, I would like encoding errors to result in empty strings in JNI as well.