Skip to content

fix(chat): avoid ClassCastException when building FileParameters - #6465

Open
mahibi wants to merge 1 commit into
masterfrom
bugfix/noid/fixClassCastExceptionForFileParams
Open

fix(chat): avoid ClassCastException when building FileParameters#6465
mahibi wants to merge 1 commit into
masterfrom
bugfix/noid/fixClassCastExceptionForFileParams

Conversation

@mahibi

@mahibi mahibi commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

ChatMessageUi.messageParameters is built via Kotlin's toMap(), which returns a Collections.SingletonMap for a single entry instead of a HashMap.
Both call sites unsafely cast it to HashMap<String?, HashMap<String?, String?>>?, which crashes whenever a message has exactly one rich-object parameter (e.g. a plain file share) - the common case for FileParameters.

Build real HashMap instances from messageParameters instead of casting it.
Also removes a runCatching block in LazyListState.visibleItemsWithThreshold() that silently swallowed the same ClassCastException, which was hiding this bug and causing file id lookups to fail there.

fixed crash:

❯ 2026-08-07 12:02:40.777 28629-28629 NextcloudT...pplication com.nextcloud.talk2                  E  Uncaught exception in thread "main" (Fix with AI)
                                                                                                      java.lang.ClassCastException: java.util.Collections$SingletonMap cannot be cast to
  java.util.HashMap
                                                                                                          at com.nextcloud.talk.ui.chat.MediaMessageKt.MediaMessage(MediaMessage.kt:71)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.ChatMessageView$lambda$5$1(ChatMessageView.kt:151)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.$r8$lambda$BiaHdWRFag7qJIfvY45CugWWbIY(ChatMessageView.kt:0)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt$$ExternalSyntheticLambda1.invoke(D8$$SyntheticClass:0)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:122)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:52)
                                                                                                          at
  com.nextcloud.talk.ui.chat.SwipeToReplyContainerKt.SwipeToReplyContainer(SwipeToReplyContainer.kt:57)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.ChatMessageView$lambda$5(ChatMessageView.kt:114)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt$$ExternalSyntheticLambda4.invoke(D8$$SyntheticClass:0)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:122)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:52)
                                                                                                          at
  androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:408)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.ChatMessageView(ChatMessageView.kt:105)

It happened to me after i tested #6327

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

  ChatMessageUi.messageParameters is built via Kotlin's toMap(), which
  returns a Collections.SingletonMap for a single entry instead of a
  HashMap. Both call sites unsafely cast it to
  HashMap<String?, HashMap<String?, String?>>?, which crashes whenever a
  message has exactly one rich-object parameter (e.g. a plain file
  share) - the common case for FileParameters.

  Build real HashMap instances from messageParameters instead of casting
  it. Also removes a runCatching block in
  LazyListState.visibleItemsWithThreshold() that silently swallowed the
  same ClassCastException, which was hiding this bug and causing file id
  lookups to fail there.

fixed crash:

❯ 2026-08-07 12:02:40.777 28629-28629 NextcloudT...pplication com.nextcloud.talk2                  E  Uncaught exception in thread "main" (Fix with AI)
                                                                                                      java.lang.ClassCastException: java.util.Collections$SingletonMap cannot be cast to
  java.util.HashMap
                                                                                                          at com.nextcloud.talk.ui.chat.MediaMessageKt.MediaMessage(MediaMessage.kt:71)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.ChatMessageView$lambda$5$1(ChatMessageView.kt:151)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.$r8$lambda$BiaHdWRFag7qJIfvY45CugWWbIY(ChatMessageView.kt:0)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt$$ExternalSyntheticLambda1.invoke(D8$$SyntheticClass:0)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:122)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:52)
                                                                                                          at
  com.nextcloud.talk.ui.chat.SwipeToReplyContainerKt.SwipeToReplyContainer(SwipeToReplyContainer.kt:57)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.ChatMessageView$lambda$5(ChatMessageView.kt:114)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt$$ExternalSyntheticLambda4.invoke(D8$$SyntheticClass:0)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:122)
                                                                                                          at
  androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:52)
                                                                                                          at
  androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:408)
                                                                                                          at
  com.nextcloud.talk.ui.chat.ChatMessageViewKt.ChatMessageView(ChatMessageView.kt:105)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi
mahibi requested a review from rapterjet2004 August 7, 2026 10:33
@mahibi mahibi self-assigned this Aug 7, 2026
@mahibi mahibi added the 3. to review Waiting for reviews label Aug 7, 2026
@mahibi mahibi modified the milestones: 24.0.3, 24.1.0, 25.0.0 Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/talk-android/actions/runs/31170584090/artifacts/8991684749
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews AI assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant