diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt index 00cbe0aa85..9bc727541d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt @@ -30,7 +30,11 @@ internal fun RealmObject.assertIsManaged() { */ internal fun RealmList.clearWith(delete: (T) -> Unit) { while (!isEmpty()) { + val previousSize = size first()?.let { delete.invoke(it) } + if (previousSize != size + 1) { + error("`clearWith` MUST delete all elements of the RealmList") + } } }