1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Apply group memberships: be more defensive with potentially missing members.

This should never happen, but it has:

kotlin.TypeCastException: null cannot be cast to non-null type com.etesync.syncadapter.resource.LocalContact
at com.etesync.syncadapter.resource.LocalGroup$Companion.applyPendingMemberships(LocalGroup.kt:66)
at com.etesync.syncadapter.syncadapter.ContactsSyncManager.postProcess(ContactsSyncManager.kt:122)
at com.etesync.syncadapter.syncadapter.SyncManager.performSync(SyncManager.kt:169)
at com.etesync.syncadapter.syncadapter.ContactsSyncAdapterService$ContactsSyncAdapter.onPerformSync(ContactsSyncAdapterService.kt:59)
at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:259)

We call it at post process exactly because we want to make sure that all
the members already exist.

I guess a deletion on a misbehaving client (maybe even the web client?)
can cause this. Potentially also with some DAV clients.

Anyhow, it's better to be more defensive here.
This commit is contained in:
Tom Hacohen 2019-02-12 09:27:42 +00:00
parent fbc9294747
commit 69bf028481

View File

@ -63,8 +63,9 @@ class LocalGroup : AndroidGroup, LocalAddress {
// insert memberships
val membersIds = members.map {uid ->
Constants.log.fine("Assigning member: $uid")
(addressBook.findByUid(uid) as LocalContact).id!!
}
val contact = addressBook.findByUid(uid) as LocalContact?
if (contact != null) contact.id else null
}.filterNotNull()
val group = addressBook.findGroupById(id)
group.setMembers(batch, membersIds)