Fix NPE in KaptJavaLog

See https://issuetracker.google.com/issues/162446295 for more context, but in short: this will fail if the project:
* targets java 8
* consumes external libraries targeting a higher version (java 9+). This includes Android SDK 30's android.jar, which targets java 9
* has `mapDiagnosticLocations` enabled for kapt

targetElement is a nullable type, so this seems like a pretty cut-and-dry NPE fix
This commit is contained in:
Zac Sweers
2020-07-30 13:59:25 -04:00
committed by Yan Zhulanow
parent 462b752763
commit 12a6352bef
@@ -82,7 +82,7 @@ class KaptJavaLog(
}
}
if (mapDiagnosticLocations && sourceFile != null && targetElement.tree != null) {
if (mapDiagnosticLocations && sourceFile != null && targetElement?.tree != null) {
val kotlinPosition = stubLineInfo.getPositionInKotlinFile(sourceFile, targetElement.tree)
val kotlinFile = kotlinPosition?.let { getKotlinSourceFile(it) }
if (kotlinPosition != null && kotlinFile != null) {