From f491b810c71b1b0d82a2a0f9e63620239a6c1335 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 7 Jul 2023 13:31:05 +0200 Subject: [PATCH] avoid NPE in ProfileActivity because userInfo could be null reported via gplay: Exception java.lang.NullPointerException: at com.nextcloud.talk.profile.ProfileActivity$save$1.onError (ProfileActivity.kt:457) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.checkTerminated (ObservableObserveOn.java:281) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal (ObservableObserveOn.java:172) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run (ObservableObserveOn.java:255) at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run (HandlerScheduler.java:124) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:257) at android.app.ActivityThread.main (ActivityThread.java:8220) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:626) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1015) Signed-off-by: Marcel Hibbe --- .../java/com/nextcloud/talk/profile/ProfileActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt b/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt index 136b364ee2..e54e8d4692 100644 --- a/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt @@ -434,7 +434,7 @@ class ProfileActivity : BaseActivity() { private fun save() { for (item in adapter!!.displayList!!) { // Text - if (item.text != userInfo!!.getValueByField(item.field)) { + if (item.text != userInfo?.getValueByField(item.field)) { val credentials = ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token) ncApi.setUserData( credentials, @@ -458,7 +458,7 @@ class ProfileActivity : BaseActivity() { } override fun onError(e: Throwable) { - item.text = userInfo!!.getValueByField(item.field)!! + item.text = userInfo?.getValueByField(item.field) Toast.makeText( applicationContext, String.format( @@ -479,7 +479,7 @@ class ProfileActivity : BaseActivity() { } // Scope - if (item.scope != userInfo!!.getScopeByField(item.field)) { + if (item.scope != userInfo?.getScopeByField(item.field)) { saveScope(item, userInfo) } adapter!!.updateFilteredList() @@ -586,7 +586,7 @@ class ProfileActivity : BaseActivity() { } override fun onError(e: Throwable) { - item.scope = userInfo!!.getScopeByField(item.field) + item.scope = userInfo?.getScopeByField(item.field) Log.e(TAG, "Failed to saved: " + item.scope + " as " + item.field, e) }