IR/Android: place the cache field first

to avoid NPEs if it is used during instance initialization.
This commit is contained in:
pyos
2021-11-19 10:33:13 +01:00
committed by Alexander Udalov
parent 55d1fdfbc2
commit 001ddda935
2 changed files with 5 additions and 2 deletions
@@ -201,7 +201,8 @@ private class AndroidIrTransformer(val extension: AndroidIrExtension, val plugin
return super.visitClassNew(declaration)
if ((containerOptions.cache ?: extension.getGlobalCacheImpl(declaration)).hasCache) {
declaration.declarations += declaration.getCacheField()
// Place the field first so that it is initialized before any init blocks.
declaration.declarations.add(0, declaration.getCacheField())
declaration.declarations += declaration.getClearCacheFun()
declaration.declarations += declaration.getCachedFindViewByIdFun()
}
@@ -33,9 +33,11 @@ class MyActivity(): Activity() {
} as T?
}
private val textViewString = textView1.toString()
public fun box(): String {
val result = when {
textView1.toString() == "TextView" && password.toString() == "EditText" && login.toString() == "Button" -> "OK"
textViewString == "TextView" && password.toString() == "EditText" && login.toString() == "Button" -> "OK"
else -> ""
}