Uploaded image for project: 'Realm Java SDK'
  1. Realm Java SDK
  2. RJAVA-823

java.lang.IllegalStateException: Only valid, managed RealmLists can be frozen

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      Goal

      I was using Kotlin Flow with the default InternalFlowFactory(returnFrozenObjects = true). I have a coroutine launched by the viewLifeCycleScope of a fragment. Inside that lifecycle i have a realm query and create a flow from it that updates the UI. I would suspect i can safely delete the object where the flow is attached to.

      Actual Results

      Upon deletion the app crashes. There is no reference to my code in the logs. The crash goes away if i set InternalFlowFactory(returnFrozenObjects = false), however this is not what i want by default.

      JNI DETECTED ERROR IN APPLICATION: JNI NewLocalRef called with pending exception java.lang.IllegalStateException: Only valid, managed RealmLists can be frozen.
          java_vm_ext.cc:577]   at io.realm.RealmList io.realm.RealmList.freeze() (RealmList.java:168)
          java_vm_ext.cc:577]   at void io.realm.internal.coroutines.InternalFlowFactory$from$5$listener$1.onChange(io.realm.RealmList) (InternalFlowFactory.kt:324)
          java_vm_ext.cc:577]   at void io.realm.internal.coroutines.InternalFlowFactory$from$5$listener$1.onChange(java.lang.Object) (InternalFlowFactory.kt:34)
          java_vm_ext.cc:577]   at void io.realm.internal.ObservableCollection$RealmChangeListenerWrapper.onChange(java.lang.Object, io.realm.OrderedCollectionChangeSet) (ObservableCollection.java:39)
          java_vm_ext.cc:577]   at void io.realm.internal.ObservableCollection$CollectionObserverPair.onChange(java.lang.Object, io.realm.internal.OsCollectionChangeSet) (ObservableCollection.java:20)
          java_vm_ext.cc:577]   at void io.realm.internal.ObservableCollection$Callback.onCalled(io.realm.internal.ObservableCollection$CollectionObserverPair, java.lang.Object) (ObservableCollection.java:64)
          java_vm_ext.cc:577]   at void io.realm.internal.ObservableCollection$Callback.onCalled(io.realm.internal.ObserverPairList$ObserverPair, java.lang.Object) (ObservableCollection.java:54)
          java_vm_ext.cc:577]   at void io.realm.internal.ObserverPairList.foreach(io.realm.internal.ObserverPairList$Callback) (ObserverPairList.java:109)
          java_vm_ext.cc:577]   at void io.realm.internal.OsList.notifyChangeListeners(long) (OsList.java:314)
          java_vm_ext.cc:577]   at void android.os.MessageQueue.nativePollOnce(long, int) (MessageQueue.java:-2)
          java_vm_ext.cc:577]   at android.os.Message android.os.MessageQueue.next() (MessageQueue.java:335)
          java_vm_ext.cc:577]   at void android.os.Looper.loop() (Looper.java:183)
          java_vm_ext.cc:577]   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:7656)
          java_vm_ext.cc:577]   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
          java_vm_ext.cc:577]   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:592)
          java_vm_ext.cc:577]   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:947)
          java_vm_ext.cc:577] 
          java_vm_ext.cc:577]     in call to NewLocalRef
          java_vm_ext.cc:577]     from void android.os.MessageQueue.nativePollOnce(long, int)
      

      Shouldn't the InternalFlowFactory check whether the object is still valid?
      I tried with the RxJava version and also get the same error.

      Version of Realm and tooling

      Realm version(s): 10.2.0

      Realm Sync feature enabled: No

      Android Studio version: 4.1.1

      Android Build Tools version: 29.0.3

      Gradle version: 4.1.1

      Which Android version and device(s): Pixel 3 Android 11

            Assignee:
            christian.melchior@mongodb.com Christian Melchior (Inactive)
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: