I have random rare crash that makes no sense at al...
# compose
t
I have random rare crash that makes no sense at all that seems to be generated from
Copy code
Modifier.weight(1f, fill = false)
Error:
Copy code
java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Boolean
        at xxxxx.library.LiveLiterals$LibraryDestinationKt.Boolean$arg-1$call-weight$val-tmp3_modifier$fun-$anonymous$$arg-3$call-Row$fun-$anonymous$$arg-1$call-CompositionLocalProvider$fun-$anonymous$$arg-3$call-Column$fun-$anonymous$$arg-3$call-Row$fun-$anonymous$$arg-3$call-Box$fun-AlbumEntry(Unknown Source:31)
Is there something I miss in the stack trace?
Full code for the weight:
Copy code
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.disabled) {
                    Row(modifier = Modifier.fillMaxWidth()) {
                        Text(
                            text = finalMediaItem.displayArtist,
                            maxLines = 1,
                            overflow = TextOverflow.Ellipsis,
                            style = MaterialTheme.typography.body2,
                            modifier = Modifier.weight(1f, fill = false)
                        )
a
Please file a bug with a repro case if you can. Is this using 1.0.x or 1.1.x?
And with which version of Android Studio?
t
1.1 A6 and AS Bumblebee B1. This happens completely randomly, any idea on what to search for to repro?
c
The exception seems to indicate that the code generation for live literals misinterpreted the
weight
parameter as a
Boolean
somewhere. Try just editing the literal value of this parameter or the value of the
fill
parameter.
t
What do you mean by editing the literal ? Those are the values I need, so you mean use true and not 1f for test or something else ?
Ok I think I understand what you mean and editing those values dozens of time does not crash but properly update on device. One annoying thing is that it's completely instant so if you have weight(0.1f) and press backspace to delete the 1 to put a 2, it crash because weight 0 is illegal.
c
We should probably build more debouncing into Live Literals if we haven't already @nosuid
t
So as I was playing with that file today, I did a million tests and there's just no pattern at all here. 😞 This will happen very randomly after the first reload of the app due to code modification on non literal things but even with the same modification it won't happen at 100%.
Like this file have :
Copy code
@ExperimentalFoundationApi
public fun <T : Any> LazyGridScope.items(
    lazyPagingItems: LazyPagingItems<T>,
    itemContent: @Composable LazyItemScope.(value: T?) -> Unit
) {
    items(lazyPagingItems.itemCount) { index ->
        itemContent(lazyPagingItems[index])
    }
}
Just removing the
public
suffix trigger this crash but something like 25% of the time only. And interestingly that function is not used anywhere in the app.