realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.81k stars 578 forks source link

Crash on start: "terminating with uncaught exception of type facebook::jni::JniException: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available" #6483

Open tran-simon opened 9 months ago

tran-simon commented 9 months ago

How frequently does the bug occur?

Once

Description

Crash happens only in production on one device. We do not have access to the device and could not reproduce on our personnal devices, but we asked the person to reinstall our app and they still get the same crash as soon as they open the app and Realm finishes syncing.

Relevant package versions:

Package Version
realm 11.3.1
react-native 0.70.14
reactnativereanimated 3.5.4
@react-natvigation/native 6.1.9
@reactnavigation/bottomtabs 6.5.11
@reactnavigation/nativestack 6.9.17
reactnativevector-icons 10.0.3

We are not using @realm-react

The issue seems similar to #5393, but @FN-FAL113 's fix is not applicable for us (we never use "new Intl.NumberFormat(...)")

Stacktrace & log output

terminating with uncaught exception of type facebook::jni::JniException: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 13884 >>> com.XXX.XXX <<<

backtrace:
  #00  pc 0x00000000000537d4  /apex/com.android.runtime/lib64/bionic/libc.so (abort+168)
  #01  pc 0x000000000009ce88  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libc++_shared.so (BuildId: ece72a2ebc3774a1be9fd21271258acd3bcdfaa7)
  #02  pc 0x000000000009d07c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libc++_shared.so (BuildId: ece72a2ebc3774a1be9fd21271258acd3bcdfaa7)
  #03  pc 0x00000000000aead0  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libc++_shared.so (BuildId: ece72a2ebc3774a1be9fd21271258acd3bcdfaa7)
  #04  pc 0x00000000000aea68  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libc++_shared.so (std::terminate()+36) (BuildId: ece72a2ebc3774a1be9fd21271258acd3bcdfaa7)
  #05  pc 0x00000000000723d0  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #06  pc 0x00000000001ba260  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #07  pc 0x000000000011179c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #08  pc 0x000000000010d4c0  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #09  pc 0x000000000007dc70  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #10  pc 0x000000000008fa98  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #11  pc 0x00000000000916b4  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #12  pc 0x0000000000090d7c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #13  pc 0x000000000007dd80  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #14  pc 0x000000000007c834  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #15  pc 0x00000000000e03d8  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #16  pc 0x000000000007dc70  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #17  pc 0x000000000008fa98  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #18  pc 0x00000000000916b4  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #19  pc 0x0000000000090d7c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #20  pc 0x000000000007dd80  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #21  pc 0x000000000007d938  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #22  pc 0x000000000008fabc  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #23  pc 0x00000000000916b4  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #24  pc 0x0000000000090d7c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #25  pc 0x000000000007dd80  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #26  pc 0x000000000007d938  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #27  pc 0x000000000008fabc  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #28  pc 0x00000000000916b4  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #29  pc 0x0000000000090d7c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #30  pc 0x000000000007dd80  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #31  pc 0x0000000000070938  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 8e97a959cff3cce43cb28c3fbbc5a9fc14b6eabd)
  #32  pc 0x00000000003c8f6c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #33  pc 0x00000000003f2874  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #34  pc 0x00000000004ce7bc  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #35  pc 0x00000000004e39dc  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #36  pc 0x00000000004c080c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #37  pc 0x00000000004f072c  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #38  pc 0x00000000004f08d0  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #39  pc 0x00000000004f1640  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/split_config.arm64_v8a.apk!librealm.so (BuildId: 32297eb3dece7880)
  #40  pc 0x0000000000018028  /system/lib64/libutils.so (android::Looper::pollInner(int)+1064)
  #41  pc 0x0000000000017b9c  /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+116)
  #42  pc 0x0000000000168b34  /system/lib64/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int)+48)
  #43  pc 0x000000000032f514  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (art_jni_trampoline+116)
  #44  pc 0x0000000000a38b30  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.MessageQueue.next+304)
  #45  pc 0x0000000000a35610  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loopOnce+96)
  #46  pc 0x0000000000a35508  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loop+1112)
  #47  pc 0x00000000005b9798  /apex/com.android.art/lib64/libart.so (nterp_helper+152)
  #48  pc 0x00000000004c865a  /data/app/~~iEnFUspIVwZN0AeQGTKyJw==/com.XXX.XXX-31So7SexisJdk0fGU9iEaw==/oat/arm64/base.vdex (com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run+74)
  #49  pc 0x000000000041af98  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (java.lang.Thread.run+72)
  #50  pc 0x000000000033eda4  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+612)
  #51  pc 0x0000000000239d54  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+144)
  #52  pc 0x000000000053a1b0  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1600)
  #53  pc 0x00000000000bb728  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+208)
  #54  pc 0x000000000005501c  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+68)

Can you reproduce the bug?

No

Reproduction Steps

No response

Version

11.3.1

What services are you using?

Both Atlas Device Sync and Atlas App Services

Are you using encryption?

No

Platform OS and version(s)

Android 13 (SDK 33)

Build environment

Release version on the play store running on a samsung phone

Cocoapods version

No response

kneth commented 9 months ago

It is hard to tell exactly but our best guess is that it is related to your ProGuard configuration. Please take a look at https://www.mongodb.com/docs/realm/sdk/react-native/install/#extend-android-proguard-configuration

tran-simon commented 9 months ago

I managed to get some more information on the issue

The line that caused the crash is name.toLowerCase() when name is a string that contains an accent "é" or an emoji (😀).

I can also cause a crash by using Intl.NumberFormat().format(), similar to @FN-FAL113's issue #5393

I've spent some time investigating, and it seems like realm is responsible somehow.

Causing

As soon as a realm object listener fires, I can't use toLowerCase() on strings with accents or emojis

    const thing = realm?.objects('Thing')?.[0]
    thing?.addListener(()=>{
      console.log('CRASHES 😀'.toLowerCase());
    }) 

It will crash for the rest of the lifetime of the app, no matter where the toLowerCase() is

  const [state, setState] = useState(false)

  useEffect(() => {
    const thing = realm?.objects('Thing')?.[0]
    thing?.addListener(()=>{
      setState(true)
    }) 
  }, []);

  useEffect(() => {
    if (state) {
      console.log('2 CRASHES 😀'.toLowerCase());
    }
  }, [state]);

Preventing

If I use toLowerCase() before the listener fires, it will not crash anywhere else

  const [state, setState] = useState(false)

  useEffect(() => {
    console.log('PREVENT CRASH 😀'.toLowerCase());
  }, []);

  useEffect(() => {
    const thing = PreferenceRealm.realm?.objects(Preferences.schema.name)?.[0]
    thing?.addListener(()=>{
      console.log('DOES NOT CRASH 😀'.toLowerCase());
      setState(true)
    }) 
  }, []);

  useEffect(() => {
    if (state) {
      console.log('DOES NOT CRASH 😀'.toLowerCase());
    }
  }, [state]);

Atlas device sync

It might be related to atlas device sync? In my original app, I could not make it crash if I did a new Realm.open() with no sync configs.

      const defaultConfig = {
        path: 'synced-realm',
        schema: [Thing],
        sync: {
          user: realmUser,
          partitionValue: realmUser.id,
          clientReset: {
            mode: Realm.ClientResetMode.RecoverOrDiscardUnsyncedChanges,
            onRecovery: () => {
              return;
            },
            onDiscard: () => {
              console.warn('Discarding unsynced changes.');
            },
            onFallback: onSyncedFallback,
          },
        },
      }

      // This will cause the crash later when we call `toLowerCase()`
      const {  ...config } = defaultConfig;
      const realm = await Realm.open(config);

      // This will *not* cause the crash later when we call `toLowerCase()`
      const { sync, ...config } = defaultConfig;
      const realm = await Realm.open(config);

Reproducing

I tried to create a new project with the same dependencies, but could not manage to make it crash. I did not try to enable sync.

Temporary fix

I added these lines at the top of my index.js

'é'.toLowerCase();
Intl.NumberFormat().format(0)

This seems to prevent the crash everywhere else

Hopefully this can help

susonthapa commented 3 months ago

We are running into similar issues in our app. We recently switched to using @realm/react for one of the screens and some of the users are facing the following crashes. This is happening on Android only.

java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
at toLocaleString (native)
at [redacted] (address at index.android.bundle:1)
at [redacted] (address at index.android.bundle:1)
at renderWithHooks (address at index.android.bundle:1)
at beginWork$1 (address at index.android.bundle:1)
at performUnitOfWork (address at index.android.bundle:1)
at workLoopSync (address at index.android.bundle:1)
at renderRootSync (address at index.android.bundle:1)
at performSyncWorkOnRoot (address at index.android.bundle:1)
at flushSyncCallbacks (address at index.android.bundle:1)
at scheduleUpdateOnFiber (address at index.android.bundle:1)
at dispatchReducerAction (address at index.android.bundle:1)
at listenerCallback (address at index.android.bundle:1)
at anonymous (address at index.android.bundle:1)

We temporarily fixed the issue by using a custom function to format numbers. We don't have any clue why this is happening. The code was working fine before introducing @realm/react to make the screen reactive.

aclelland-netfore commented 3 months ago

I just ran into a similar problem with a similar fix (happening in my dev and prod builds). Specifically relating to https://github.com/realm/realm-js/issues/5393 as it works again every time once the app reloads. One difference is that just calling create() didn't cause the app to crash, but nesting create() calls (adding the objects that just have the text "(Exception)" to another new realm object.

const item = realm.create(ItemRealm, {...}, Realm.UpdateMode.Modified) // console logs will show "(Exception)" on each attribute
const container = realm.create(ContainerRealm, {..., item: item, ...}, Realm.UpdateMode.Modified) // this line is what kills the app

My use case is calling the useQuery hook to return a list of realms followed by a useMemo which sorts them using a.localCompare(b) and similar to others adding "a".localCompare("b") to my index fixes the issue. It took me longer to find the issue as my logs never actually mention the localCompare anywhere.

const useMyItems = (id: number) => {
     const _items = useQuery(
         ItemRealm,
         () => collection.filtered("parentId = $0", id),
         [id]
    )

    // this is what kills the app
    return useMemo(() => {
       return _items.map((item) => nonRealmItem(item)).sort((a,b) => .... a.name.localCompare(b,name) ....)
    }, [_items])
}

logcat

08-28 13:41:23.076 12969 13338 E ReactNativeJS: RangeError: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
08-28 13:41:23.076 12969 13338 E ReactNativeJS: 
08-28 13:41:23.076 12969 13338 E ReactNativeJS: This error is located at:
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in Unknown (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in View
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in Unknown (created by TouchableOpacity)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in TouchableOpacity (created by TouchableOpacity)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in TouchableOpacity (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in View (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in View (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in VirtualizedListCellContextProvider (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in CellRenderer (created by VirtualizedList)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in View (created by ScrollView)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in RCTScrollView (created by ScrollView)
08-28 13:41:23.076 12969 13338 E ReactNativeJS:     in AndroidSwipeRefreshLayout (created by RefreshControl)

package.json

some values from my package.json that might be relevant based on other posts

    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",

    "expo": "^49.0.0",
    "react-native": "0.72.10",

    "react-native-gesture-handler": "~2.12.0",
    "react-native-reanimated": "~3.5.4",
    "react-native-screens": "~3.22.0",

    "@realm/react": "^0.6.2",
    "realm": "^11.10.2",