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

Issue

my app crashed and the logcat shows this”” JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0″”

the logcat shows this

03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] string:


‘ZA_SPEENA_JALLABI__YAMA_LALAI_ME_GHANAM__RANG_DE_😉😍(_BY_ARYANA_SAEED_)(128k).mp3′ 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] in call to NewStringUTF 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] from org.aitech.medialibrary.interfaces.media.MediaWrapper[] org.aitech.medialibrary.MedialibraryImpl.nativeGetSortedPagedAudio(int, boolean, int, int) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] “arch_disk_io_1″ prio5 tid20 Runnable 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | group”main” sCount0 dsCount0 obj0x13054160 self0xdd476000 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | sysTid25517 nice0 cgrpdefault sched0/0 handle0xf4923080 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | stateR schedstat( 0 0 0 ) utm10 stm8 core3 HZ100 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | stack0xdccb7000-0xdccb9000 stackSize1036KB 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | held mutexes “mutator lock”(shared held) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #00 pc 00004e64 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext)+23) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #01 pc 00003665 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #02 pc 0026bc55 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream >&, int, char const*, art::mirror::ArtMethod*)+84) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #03 pc 0024e367 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream >&) const+158) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #04 pc 000b6d7b /system/lib/libart.so (art::JniAbort(char const*, char const*)+610) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #05 pc 000b74a1 /system/lib/libart.so (art::JniAbortF(char const*, char const*, …)+68) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #06 pc 000b9a5b /system/lib/libart.so (art::ScopedCheck::Check(bool, char const*, …) (.constprop.129)+922) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #07 pc 000c3545 /system/lib/libart.so (art::CheckJNI::NewStringUTF(_JNIEnv*, char const*)+44) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #08 pc 000bc843 /data/app/org.aitech.ai.debug-1/lib/arm/libmla.so (mediaToMediaWrapper(_JNIEnv*, fields*, std::__ndk1::shared_ptr const&)+514) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #09 pc 000b27af /data/app/org.aitech.ai.debug-1/lib/arm/libmla.so (???) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #10 pc 000b28f7 /data/app/org.aitech.ai.debug-1/lib/arm/libmla.so (getPagedAudio(_JNIEnv*, _jobject*, int, unsigned char, int, int)+46) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #11 pc 00a7a383 /data/dalvik-cache/arm/data@app@org.aitech.ai.debug-1@base.apk@classes.dex (Java_org_videolan_medialibrary_MedialibraryImpl_nativeGetSortedPagedAudio__IZII+110) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.medialibrary.MedialibraryImpl.nativeGetSortedPagedAudio(Native method) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.medialibrary.MedialibraryImpl.getPagedAudio(MedialibraryImpl.java:194) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.ai.providers.medialibrary.TracksProvider.getPage(TracksProvider.kt:63) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.ai.providers.medialibrary.TracksProvider.getPage(TracksProvider.kt:33) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.ai.providers.medialibrary.MedialibraryProvider$MLDataSource.loadInitial(MedialibraryProvider.kt:127) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.PositionalDataSource.dispatchLoadInitial(PositionalDataSource.java:362) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.TiledPagedList.(TiledPagedList.java:112) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.PagedList.create(PagedList.java:452) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.PagedList$Builder.build(PagedList.java:611) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.LivePagedListBuilder$1.compute(LivePagedListBuilder.java:202) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.LivePagedListBuilder$1.compute(LivePagedListBuilder.java:167) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.lifecycle.ComputableLiveData$2.run(ComputableLiveData.java:101) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at java.lang.Thread.run(Thread.java:818) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] string: ‘ZA_SPEENA_JALLABI__YAMA_LALAI_ME_GHANAM__RANG_DE_😉😍(_BY_ARYANA_SAEED_)(128k).mp3’ 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] in call to NewStringUTF 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] from org.aitech.medialibrary.interfaces.media.MediaWrapper[] org.aitech.medialibrary.MedialibraryImpl.nativeGetSortedPagedAudio(int, boolean, int, int) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] “arch_disk_io_1″ prio5 tid20 Runnable 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | group”main” sCount0 dsCount0 obj0x13054160 self0xdd476000 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | sysTid25517 nice0 cgrpdefault sched0/0 handle0xf4923080 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | stateR schedstat( 0 0 0 ) utm10 stm8 core3 HZ100 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | stack0xdccb7000-0xdccb9000 stackSize1036KB 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] | held mutexes “mutator lock”(shared held) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #00 pc 00004e64 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #01 pc 00003665 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #02 pc 0026bc55 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream >&, int, char const*, art::mirror::ArtMethod*)+84) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #03 pc 0024e367 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream >&) const+158) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #04 pc 000b6d7b /system/lib/libart.so (art::JniAbort(char const*, char const*)+610) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #05 pc 000b74a1 /system/lib/libart.so (art::JniAbortF(char const*, char const*, …)+68) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #06 pc 000b9a5b /system/lib/libart.so (art::ScopedCheck::Check(bool, char const*, …) (.constprop.129)+922) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #07 pc 000c3545 /system/lib/libart.so (art::CheckJNI::NewStringUTF(_JNIEnv*, char const*)+44) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #08 pc 000bc843 /data/app/org.aitech.ai.debug-1/lib/arm/libmla.so (mediaToMediaWrapper(_JNIEnv*, fields*, std::__ndk1::shared_ptr const&)+514) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #09 pc 000b27af /data/app/org.aitech.ai.debug-1/lib/arm/libmla.so (???) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #10 pc 000b28f7 /data/app/org.aitech.ai.debug-1/lib/arm/libmla.so (getPagedAudio(_JNIEnv*, _jobject*, int, unsigned char, int, int)+46) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] native: #11 pc 00a7a383 /data/dalvik-cache/arm/data@app@org.aitech.ai.debug-1@base.apk@classes.dex (Java_org_videolan_medialibrary_MedialibraryImpl_nativeGetSortedPagedAudio__IZII+110) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.medialibrary.MedialibraryImpl.nativeGetSortedPagedAudio(Native method) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.medialibrary.MedialibraryImpl.getPagedAudio(MedialibraryImpl.java:194) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.ai.providers.medialibrary.TracksProvider.getPage(TracksProvider.kt:63) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.ai.providers.medialibrary.TracksProvider.getPage(TracksProvider.kt:33) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at org.aitech.ai.providers.medialibrary.MedialibraryProvider$MLDataSource.loadInitial(MedialibraryProvider.kt:127) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.PositionalDataSource.dispatchLoadInitial(PositionalDataSource.java:362) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.TiledPagedList.(TiledPagedList.java:112) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.PagedList.create(PagedList.java:452) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.PagedList$Builder.build(PagedList.java:611) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.LivePagedListBuilder$1.compute(LivePagedListBuilder.java:202) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.paging.LivePagedListBuilder$1.compute(LivePagedListBuilder.java:167) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at androidx.lifecycle.ComputableLiveData$2.run(ComputableLiveData.java:101) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] at java.lang.Thread.run(Thread.java:818) 03-19 10:39:29.491 25489-25517/org.aitech.ai.debug A/art: sart/runtime/check_jni.cc:65] “””””””””””””‘

Solution

The 😉 character is U+1F609 WINKING FACE.

Its regular UTF-8 encoding is f09f9889, which matches your error. Java expects Modified UTF-8, however:

Characters with code points above U+FFFF (so-called supplementary characters) are represented by separately encoding the two surrogate code units of their UTF-16 representation. Each of the surrogate code units is represented by three bytes. This means, supplementary characters are represented by six bytes, u, v, w, x, y, and z.

You cannot use NewStringUTF for this, you will have to manually decode from UTF-8.

Cribbing from my answer here, we will do the equivalent of
Charset.forName("UTF-8").decode(bb).toString():

const char * filename  /* what you have now */;
jobject bb  env->NewDirectByteBuffer(filename, strlen(filename));

jclass cls_Charset  env->FindClass("java/nio/charset/Charset");
jmethodID mid_Charset_forName  env->GetStaticMethodID(cls_Charset, "forName", "(Ljava/lang/String;)Ljava/nio/charset/Charset;");
jobject charset  env->CallStaticObjectMethod(cls_Charset, mid_Charset_forName, env->NewStringUTF("UTF-8"));

jmethodID mid_Charset_decode  env->GetMethodID(cls_Charset, "decode", "(Ljava/nio/ByteBuffer;)Ljava/nio/CharBuffer;");
jobject cb  env->CallObjectMethod(charset, mid_Charset_decode, bb);
env->DeleteLocalRef(bb);

jclass cls_CharBuffer  env->FindClass("java/nio/CharBuffer");
jmethodID mid_CharBuffer_toString  env->GetMethodID(cls_CharBuffer, "toString", "()Ljava/lang/String;");
jstring str  env->CallObjectMethod(cb, mid_CharBuffer_toString);
// Do something with str

Answered By – Botje

Leave a Comment