Posted this originally in compose-android but got no takers, so posting here in the hopes it will have someone who might!
We have the following bit of logic:
@Composable
fun PanelContent(
viewModel: ArticlesViewModel,
magazine: ArticlesViewModel.MagazineState,
onShowSnackbar: (String) -> Unit,
) {
val articlesState by
remember(viewModel, articles) { viewModel.getArticlesState(magazine) }
.collectAsStateWithLifecycle()
articlesState?: return
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 128.dp),
Modifier.absolutePadding(top = 8.dp, left = 16.dp, right = 16.dp, bottom = 8.dp).fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
val articles = articlesState!!.map { it.articleInfo }.toSet()
...
getArticlesState
returns back a
StateFlow<Collection<ArticlesState>?>
. The null indicates the absence of any real value from our backend repository.
I'm observing that sometimes, I get a `NullPointerException`at
articlesState!!
when it re-composes. How is that possible? Wouldn't the null check earlier have tripped?