Merge pull request #1965 from nextcloud/bugfix/noid/catch-npe-on-view-bindings

Catch NPEs on view bindings
This commit is contained in:
Marcel Hibbe 2022-05-03 14:02:34 +02:00 committed by GitHub
commit cd2e9492f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 48 deletions

View File

@ -701,11 +701,17 @@ class ChatController(args: Bundle) :
showMicrophoneButton(true) showMicrophoneButton(true)
binding.messageInputView.messageInput.doAfterTextChanged { binding.messageInputView.messageInput.doAfterTextChanged {
try {
if (binding.messageInputView.messageInput.text.isEmpty()) { if (binding.messageInputView.messageInput.text.isEmpty()) {
showMicrophoneButton(true) showMicrophoneButton(true)
} else { } else {
showMicrophoneButton(false) showMicrophoneButton(false)
} }
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchronously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
}
} }
var sliderInitX = 0F var sliderInitX = 0F

View File

@ -93,7 +93,6 @@ import retrofit2.Response
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.IOException import java.io.IOException
import java.util.ArrayList
import java.util.LinkedList import java.util.LinkedList
import java.util.Locale import java.util.Locale
import javax.inject.Inject import javax.inject.Inject
@ -341,6 +340,8 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
if (activity == null) { if (activity == null) {
return return
} }
try {
binding.emptyList.emptyListViewHeadline.text = headline binding.emptyList.emptyListViewHeadline.text = headline
binding.emptyList.emptyListViewText.text = message binding.emptyList.emptyListViewText.text = message
binding.emptyList.emptyListIcon.setImageResource(errorResource) binding.emptyList.emptyListIcon.setImageResource(errorResource)
@ -348,6 +349,11 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
binding.emptyList.emptyListViewText.visibility = View.VISIBLE binding.emptyList.emptyListViewText.visibility = View.VISIBLE
binding.userinfoList.visibility = View.GONE binding.userinfoList.visibility = View.GONE
binding.loadingContent.visibility = View.GONE binding.loadingContent.visibility = View.GONE
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchronously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
}
} }
private fun createUserInfoDetails(userInfo: UserProfileData?): List<UserInfoDetailsItem> { private fun createUserInfoDetails(userInfo: UserProfileData?): List<UserInfoDetailsItem> {

View File

@ -21,12 +21,14 @@
*/ */
package com.nextcloud.talk.controllers package com.nextcloud.talk.controllers
import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.security.KeyChain import android.security.KeyChain
import android.text.TextUtils import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
@ -188,8 +190,10 @@ class ServerSelectionController :
binding.certTextView.setOnClickListener { onCertClick() } binding.certTextView.setOnClickListener { onCertClick() }
} }
@SuppressLint("LongLogTag")
private fun checkServerAndProceed() { private fun checkServerAndProceed() {
dispose() dispose()
try {
var url: String = binding.serverEntryTextInputEditText.text.toString().trim { it <= ' ' } var url: String = binding.serverEntryTextInputEditText.text.toString().trim { it <= ' ' }
binding.serverEntryTextInputEditText.isEnabled = false binding.serverEntryTextInputEditText.isEnabled = false
showserverEntryProgressBar() showserverEntryProgressBar()
@ -206,6 +210,11 @@ class ServerSelectionController :
} else { } else {
checkServer("https://$queryUrl", true) checkServer("https://$queryUrl", true)
} }
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchronously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
}
} }
private fun checkServer(queryUrl: String, checkForcedHttps: Boolean) { private fun checkServer(queryUrl: String, checkForcedHttps: Boolean) {

View File

@ -30,6 +30,7 @@ import android.os.Bundle
import android.security.KeyChain import android.security.KeyChain
import android.security.KeyChainException import android.security.KeyChainException
import android.text.TextUtils import android.text.TextUtils
import android.util.Log
import android.view.View import android.view.View
import android.webkit.ClientCertRequest import android.webkit.ClientCertRequest
import android.webkit.CookieSyncManager import android.webkit.CookieSyncManager
@ -77,7 +78,6 @@ import java.net.URLDecoder
import java.security.PrivateKey import java.security.PrivateKey
import java.security.cert.CertificateException import java.security.cert.CertificateException
import java.security.cert.X509Certificate import java.security.cert.X509Certificate
import java.util.HashMap
import java.util.Locale import java.util.Locale
import javax.inject.Inject import javax.inject.Inject
@ -183,6 +183,7 @@ class WebViewLoginController(args: Bundle? = null) : NewBaseController(
} }
override fun onPageFinished(view: WebView, url: String) { override fun onPageFinished(view: WebView, url: String) {
try {
loginStep++ loginStep++
if (!basePageLoaded) { if (!basePageLoaded) {
binding.progressBar.visibility = View.GONE binding.progressBar.visibility = View.GONE
@ -192,7 +193,9 @@ class WebViewLoginController(args: Bundle? = null) : NewBaseController(
} }
if (!TextUtils.isEmpty(username)) { if (!TextUtils.isEmpty(username)) {
if (loginStep == 1) { if (loginStep == 1) {
binding.webview.loadUrl("javascript: {document.getElementsByClassName('login')[0].click(); };") binding.webview.loadUrl(
"javascript: {document.getElementsByClassName('login')[0].click(); };"
)
} else if (!automatedLoginAttempted) { } else if (!automatedLoginAttempted) {
automatedLoginAttempted = true automatedLoginAttempted = true
if (TextUtils.isEmpty(password)) { if (TextUtils.isEmpty(password)) {
@ -209,6 +212,12 @@ class WebViewLoginController(args: Bundle? = null) : NewBaseController(
} }
} }
} }
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchronously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
}
super.onPageFinished(view, url) super.onPageFinished(view, url)
} }