From 69bf028481e2d3976bdd65a94508f2931f30bf5f Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 12 Feb 2019 09:27:42 +0000 Subject: [PATCH] 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. --- .../main/java/com/etesync/syncadapter/resource/LocalGroup.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt b/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt index 99e6fb18..2282e7de 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt @@ -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)