fix(chat): avoid ClassCastException when building FileParameters - #6465
Open
mahibi wants to merge 1 commit into
Open
fix(chat): avoid ClassCastException when building FileParameters#6465mahibi wants to merge 1 commit into
mahibi wants to merge 1 commit into
Conversation
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>
Contributor
|
APK file: https://github.com/nextcloud/talk-android/actions/runs/31170584090/artifacts/8991684749 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
It happened to me after i tested #6327
🏁 Checklist
/backport to stable-xx.x🤖 AI (if applicable)