realm-java: OrderedRealmCollectionChangeListener issue when a change causes insertion or removal
Goal
Have RealmResults filtered by a field (isBoomarked, in my case), change value of the field to insert or remove objects.
Expected Results
Change isBookmarked value on a single object, and get a changeSet with a single deletionRange or insertionRange.
Actual Results
Sometimes a “random” changeRange is included in the changeSet.
Example
When isBookmarked is changed to false on single object, the changeSet usually comes with:
- a
deletionRangewith thestartIndexof the deleted object andlength = 1-> this is correct; - a
changeRangewithstartIndex = 0andlength = 1-> this seems like a bug, and it happens very often (not always). The removed object doesn’t havestartIndex = 0.
Code (Kotlin)
where(Item::class.java).equalTo("isBookmarked", true).findAllSortedAsync("id", Sort.DESCENDING)
realm.executeTransaction { realm ->
item.isBookmarked = !item.isBookmarked
}
Version of Realm and tooling
Realm version(s): 3.1.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (10 by maintainers)
Commits related to this issue
- Test project for https://github.com/realm/realm-java/issues/4474 — committed to jpmcosta/RealmTestProject by jpmcosta 7 years ago
- Some link's field changes are not reported This is reported by https://github.com/realm/realm-java/issues/4474 The root cause is the nested links is not handled well. In some cases those indices have... — committed to realm/realm-object-store by beeender 7 years ago
- Some link's field changes are not reported (#432) This is reported by https://github.com/realm/realm-java/issues/4474 The root cause is the nested links is not handled well. In some cases those ind... — committed to realm/realm-object-store by beeender 7 years ago
- Update Object Store To dfddfa7f7bf5 Fix #4474 — committed to realm/realm-java by beeender 7 years ago
- Update Object Store (#4522) To dfddfa7f7bf5 Fix #4474 — committed to realm/realm-java by beeender 7 years ago
Do you mean the
RealmChangeListeneron thefeed? In this case no, it won’t be triggered. If theRealmObjecthas aRealmListfield, the listener on theRealmObjectwill be triggered when you remove/add element to theRealmList, but it will NOT be triggered if any list’s element’s field changes.But if the listener is on the field
RealmList<Item> items, the listener should be triggered if anyitemin theitemslistisBookMarkedchange.Let me know if it is till confusing you 😃
@jpmcosta Thanks a lot for the simple and clear demo project. I think it is very much like a bug.
First, to clarify the behaviour:
RealmObjecthas been set tonullor another one, or adding/removing element from theRealmListfield. See doc https://realm.io/docs/java/3.1.2/api/io/realm/RealmObject.html#addChangeListener-io.realm.RealmObjectChangeListener-Yeah … we should probably doc them both in both places…
So the right behaviour would be if you change one
Item, the change range should include all other elements. It actually works if you click on the first item at the first time, it will log:But if click on others, the change range will only include only one element.
To reproduce this in a realm test case:
The issue is indeed related to
parentFeed. To reproduce the issue:ItemListAdapter;@beeender I assume he would have to retain the reference to
firstItemas field ref