ViewPump icon indicating copy to clipboard operation
ViewPump copied to clipboard

Race-Condition: kotlin.KotlinNullPointerException when calling getLayoutInflator from two threads

Open ghackett opened this issue 6 years ago • 1 comments

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.

ghackett avatar Oct 09 '19 16:10 ghackett

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

drakeet avatar Jan 08 '20 05:01 drakeet

None of the framework code here supports multithreaded access

ZacSweers avatar Mar 25 '23 02:03 ZacSweers