ViewPump
ViewPump copied to clipboard
Race-Condition: kotlin.KotlinNullPointerException when calling getLayoutInflator from two threads
When calling getLayoutInflater from two threads early in the application lifecycle, it's possible to hit a KotlinNullPointerException when evaluating this lazy(NONE): https://github.com/InflationX/ViewPump/blob/master/viewpump/src/main/java/io/github/inflationx/viewpump/ViewPumpContextWrapper.kt#L24
While it is probably not advisable to get a LayoutInflater off of the main thread (and we've already fixed our callsite that was triggering this), it does appear to be a regression. We should be able to replace lazy(NONE) with lazy(PUBLICATION) to correct this crash and avoid any impact to runtime performance.
Hi @ghackett, what scenario would you access the getSystemService(LAYOUT_INFLATER_SERVICE) in two threads?
BTW, this is the old Java version, the change in Kotlin does bring about a behavior change.
https://github.com/InflationX/ViewPump/blob/ada2e6580b4fe4dfcd0cdaf63060c3028cda65ff/viewpump/src/main/java/io/github/inflationx/viewpump/ViewPumpContextWrapper.java#L86-L94
None of the framework code here supports multithreaded access