Android and iOS Access to invalidated Collection object

Apps keep on crashing because of Access to invalidated Collection object
How do i check if the object has been invalidated.

if (realmObject != null){. —> crashing over here

}

What SDK are you using and do you have a crash log/exception message that you can share?

1 Like

So we have the Chat functionality and users can delete the chat. When one user deletes the chat, it will not be visible to other user. Issues occurs when one user deletes the chat and the 2nd is still on that screen

classpath “io.realm:realm-gradle-plugin:10.8.0”

2021-09-13 01:13:09.112 6565-6565/com.app.abc E/REALM_JNI: jni: ThrowingException 9, Access to invalidated Collection object, .
2021-09-13 01:13:09.112 6565-6565/com.app.abc E/REALM_JNI: Exception has been thrown: Access to invalidated Collection object
2021-09-13 01:13:09.113 6565-6565/com.app.abc D/AndroidRuntime: Shutting down VM
2021-09-13 01:13:09.116 6565-6565/com.app.abc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.abc, PID: 6565
java.lang.IllegalStateException: Access to invalidated Collection object
at io.realm.internal.OsList.nativeSize(Native Method)
at io.realm.internal.OsList.size(OsList.java:285)
at io.realm.ManagedListOperator.size(ManagedListOperator.java:72)
at io.realm.RealmList.size(RealmList.java:599)
at com.app.abc.activity.MessageActivity.onBackPressed(MessageActivity.java:376)
at com.app.abc.activity.MessageActivity.onBackClick(MessageActivity.java:178)
at com.app.abc.activity.MessageActivity_ViewBinding$4.doClick(MessageActivity_ViewBinding.java:90)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:18)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Apps keep on crashing because of Access to invalidated Collection object.

Is that a question? Are you having the same issue? The OP’s issue was likely due to the client not observing changes in Realm. So when a Realm object was deleted on one client the other client didn’t know about it so when attempting to modify a deleted object, the error was thrown.

If you have a question or a problem with your code, perhaps opening a different thread or posting a question on StackOverflow with more details would help us to help you.