Android Extensions: Fix KT-10969 (NullPointerException when finding view in Fragment if getView() is null)

(cherry picked from commit 80f5852)
This commit is contained in:
Yan Zhulanow
2016-04-21 21:06:30 +03:00
parent 2cd0e9c8d8
commit 530ab42de6
8 changed files with 140 additions and 1 deletions
@@ -373,6 +373,17 @@ class AndroidExpressionCodegenExtension : ExpressionCodegenExtension {
}
AndroidClassType.FRAGMENT, AndroidClassType.SUPPORT_FRAGMENT -> {
iv.invokevirtual(className, "getView", "()Landroid/view/View;", false)
iv.dup()
val lgetViewNotNull = Label()
iv.ifnonnull(lgetViewNotNull)
// Return if getView() is null
iv.pop()
iv.aconst(null)
iv.areturn(viewType)
// Else return getView().findViewById(id)
iv.visitLabel(lgetViewNotNull)
loadId()
iv.invokevirtual("android/view/View", "findViewById", "(I)Landroid/view/View;", false)
}