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 <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-07-07 13:31:05 +02:00
parent 9c89d68205
commit be97c1738d
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -434,7 +434,7 @@ class ProfileActivity : BaseActivity() {
private fun save() { private fun save() {
for (item in adapter!!.displayList!!) { for (item in adapter!!.displayList!!) {
// Text // Text
if (item.text != userInfo!!.getValueByField(item.field)) { if (item.text != userInfo?.getValueByField(item.field)) {
val credentials = ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token) val credentials = ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token)
ncApi.setUserData( ncApi.setUserData(
credentials, credentials,
@ -458,7 +458,7 @@ class ProfileActivity : BaseActivity() {
} }
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
item.text = userInfo!!.getValueByField(item.field)!! item.text = userInfo?.getValueByField(item.field)
Toast.makeText( Toast.makeText(
applicationContext, applicationContext,
String.format( String.format(
@ -479,7 +479,7 @@ class ProfileActivity : BaseActivity() {
} }
// Scope // Scope
if (item.scope != userInfo!!.getScopeByField(item.field)) { if (item.scope != userInfo?.getScopeByField(item.field)) {
saveScope(item, userInfo) saveScope(item, userInfo)
} }
adapter!!.updateFilteredList() adapter!!.updateFilteredList()
@ -586,7 +586,7 @@ class ProfileActivity : BaseActivity() {
} }
override fun onError(e: Throwable) { 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) Log.e(TAG, "Failed to saved: " + item.scope + " as " + item.field, e)
} }