Modern Apps git

← Modern-Apps.git

findfamily: fix avatar crash on empty contact names

Commit
cded377ebc90279f73acab5c11e47fd217bbc1d4
Author
Vayun Mathur <[email protected]>
When
2026-11-19 02:05 UTC (17 days ago)
Parents
a2083de
UserPicture read the avatar initial with user.name.first(), which
throws NoSuchElementException for an empty name. A contact with no
display name reaches that state through the normal picker flow:
Platform.readSessionContact maps a missing DISPLAY_NAME_PRIMARY to
the empty string, and AddPersonDialog only requires the name to be
non-null before saving the User row. The bad row then crashed every
family list, map and person-detail render, on every launch.

Use firstOrNull() instead (GreenCircle already accepts a nullable
character and draws a plain circle when there is no initial), and
guard the persisted data-URI photo decode with runCatching so a
malformed base64 payload in Room fails into the image loader
instead of throwing IllegalArgumentException during composition.

Verified with ./gradlew :findfamily:testDevUnitTest (green) and
./check findfamily (lint green; the 3 detekt findings are
pre-existing in UwbHandshakeSdk36Test, proven unchanged with the
fix stashed).

Diff

findfamily/src/main/java/com/vayunmathur/findfamily/ui/UserPicture.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/UserPicture.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/UserPicture.ktindex 415435e769..1b1370d39a 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/UserPicture.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/UserPicture.kt@@ -19,17 +19,24 @@ import kotlin.io.encoding.Base64  @Composable fun UserPicture(user: User, size: Dp, grayscale: Boolean = false, onClick: () -> Unit = {}) {-    UserPicture(user.photo, user.name.first(), size, grayscale, onClick)+    // A contact with no display name is stored with an empty name (the picker+    // maps a missing DISPLAY_NAME to ""); first() on it would throw and crash+    // every list/map render of that person. An absent initial just draws the+    // plain circle.+    UserPicture(user.photo, user.name.firstOrNull(), size, grayscale, onClick) }  @Composable-fun UserPicture(userPhoto: String?, firstChar: Char, size: Dp, grayscale: Boolean, onClick: () -> Unit) {+fun UserPicture(userPhoto: String?, firstChar: Char?, size: Dp, grayscale: Boolean, onClick: () -> Unit) {     val context = androidx.compose.ui.platform.LocalContext.current     val modifier = Modifier.clip(CircleShape).size(size).border(2.dp, MaterialTheme.colorScheme.primary, CircleShape).invisibleClickable(onClick)     if(userPhoto != null) {         val userOutput: Any = if(userPhoto.startsWith("data")) {             val cleanString = userPhoto.substringAfter("base64,")-            Base64.UrlSafe.decode(cleanString)+            // The photo string is persisted in Room; a malformed base64 payload+            // must fail into the image loader (which shows nothing) rather than+            // throwing IllegalArgumentException during composition.+            runCatching { Base64.UrlSafe.decode(cleanString) }.getOrElse { userPhoto }         } else userPhoto         AsyncImage(             ImageRequest.Builder(context)