Zhuinden / realm-book-example

This is an example rewrite of AndroidHive's messy tutorial, accompanying the following article on Realm.
https://medium.com/@Zhuinden/how-to-use-realm-for-android-like-a-champ-and-how-to-tell-if-youre-doing-it-wrong-ac4f66b7f149
Other
80 stars 19 forks source link

A weird crash bug involving deletion #12

Closed Zhuinden closed 6 years ago

Zhuinden commented 6 years ago

screenshot from 2017-12-14 17-23-28

Theoretically this should never happen, but apparently it does.

Investigate.

Zhuinden commented 6 years ago
12-15 21:00:35.497 2524-2524/com.zhuinden.realmbookexample E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.zhuinden.realmbookexample, PID: 2524
                                                                             java.lang.IllegalStateException: Object is no longer valid to operate on. Was it deleted by another thread?
                                                                                 at io.realm.internal.UncheckedRow.nativeGetString(Native Method)
                                                                                 at io.realm.internal.UncheckedRow.getString(UncheckedRow.java:157)
                                                                                 at io.realm.BookRealmProxy.realmGet$title(BookRealmProxy.java:131)
                                                                                 at com.zhuinden.realmbookexample.data.entity.Book.getTitle(Book.java:33)
                                                                                 at com.zhuinden.realmbookexample.paths.books.BooksAddBookView.bind(BooksAddBookView.java:86)
                                                                                 at com.zhuinden.realmbookexample.paths.books.BooksActivity.showEditBookDialog(BooksActivity.java:134)
                                                                                 at com.zhuinden.realmbookexample.paths.books.BooksPresenter.showEditDialog(BooksPresenter.java:71)
                                                                                 at com.zhuinden.realmbookexample.paths.books.BooksAdapter$BookViewHolder$2.onClick(BooksAdapter.java:105)

Amazingly, it seems to happen if I... uh... delete from the Realm then click quickly.

Zhuinden commented 6 years ago

...I'll just add a validity check before the bind...

Zhuinden commented 6 years ago

Worked around in https://github.com/Zhuinden/realm-book-example/commit/8bb7e578951f482097cd29e8015aa4839ed74296