Currently, we ignore the case when getActivity() return null
fun ContactsFragment.fooWithPermissionCheck() {
if (PermissionUtils.hasSelfPermissions(activity, *PERMISSION_FOO) || Settings.canDrawOverlays(activity)) {
foo()
} else {
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity!!.getPackageName())) // NPE if activity is null
activity.startActivityForResult(intent, REQUEST_FOO)
}
}
We should take care when getActivity() return null. The following code is just one idea I came up.
fun ContactsFragment.fooWithPermissionCheck() {
val activity = activity ?: return // add this
if (PermissionUtils.hasSelfPermissions(activity, *PERMISSION_FOO) || Settings.canDrawOverlays(activity)) {
foo()
} else {
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity.getPackageName()))
activity.startActivityForResult(intent, REQUEST_FOO)
}
}
See #482
Are we only going to add the check for Kotlin-based code generation, since it would break compilation? Or rather, do we also want to add this null check to our ProcessorUnits in Java?
I would like to add null check in Java since it should happens in Java, too.
馃檱
@tomoya0x00 Just in case, are you working on this issue?
@hotchemi Yes!
But I'm sorry.
Currently, I prioritize other tasks, and work on this issue will be resumed in latter half of next week.
@hotchemi Thank you for your review!! ( #511 )
If you like, I'd create PR on your idea during the weekend.
@tomoya0x00 Go ahead thank you!
Will be released in next milestone!