https://github.com/zach-klippenstein/reproduce-setcontent-crash
Reproducer for https://issuetracker.google.com/issues/157430448
https://github.com/zach-klippenstein/reproduce-setcontent-crash
Last synced: about 1 month ago
JSON representation
Reproducer for https://issuetracker.google.com/issues/157430448
- Host: GitHub
- URL: https://github.com/zach-klippenstein/reproduce-setcontent-crash
- Owner: zach-klippenstein
- Created: 2020-05-26T04:40:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T20:49:27.000Z (over 4 years ago)
- Last Synced: 2025-01-29T08:11:51.424Z (3 months ago)
- Language: Kotlin
- Homepage:
- Size: 142 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This repository contains a few minimal reproducers for a bug where the Compose runtime throws an
exception when calling `ViewGroup.setContent` to update a Composition as a side effect of clicking
a `Button` in that composition.The crash seems to be triggered by the `onClick` handler of a `Button` inside a `setContent` call
capturing parameters or variables from the method that calls `setContent` and triggering a
trampolined `setContent` call. It does _not_ occur if the lambda does not capture.There are four similar cases presented in this repo. All consist of a `FrameLayout` that calls
`ViewGroup.setContent` to set a composition that contains a single `Button` which displays a counter
value, and when clicked updates the counter and calls `setContent` again.
- CrashyView
-
This is the most minimal reproducer I could come up with. The view initializes itself by calling
`update` with a zero counter, and when the button is clicked, it calls `update` again with an
incremented counter value. Note that the counter argument is captured by this lambda in order to
add to it. - HappyView
-
This is a copy of `CrashyView` where `update` takes no parameters, and instead the counter value is
stored as a property in the `FrameLayout`. The `onClick` lambda does not capture, and there's no
crash. - IndirectCrashyView: crashyUpdate
-
This is a more indirect version of `CrashyView`, with a simple presenter. The `update` method takes
a `ViewModel` that contains a function. The button's click handler is passed a lambda that calls
the click handler from the view model. The lambda captures the `ViewModel` argument, and it crashes. - IndirectCrashyView: happyUpdate
-
This is an exact copy of `crashyUpdate`, but instead of creating an extra lambda just to call the
`ViewModel`'s click handler, it passes the handler directly. There's no lambda, and there's no
capture, so there's no crash.