Avoid NPE in loadAvatarImage

Exception java.lang.NullPointerException:
  at com.nextcloud.talk.extensions.ImageViewExtensionsKt.replaceAvatar
  at com.nextcloud.talk.utils.DisplayUtils.loadAvatarImage (DisplayUtils.java:465)
  at com.nextcloud.talk.controllers.ProfileController$uploadAvatar$1.onNext (ProfileController.kt:645)
  at com.nextcloud.talk.controllers.ProfileController$uploadAvatar$1.onNext (ProfileController.kt:639)
  at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal (ObservableObserveOn.java:201)
  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.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8751)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-23 12:10:56 +01:00
parent 3dcd5b3264
commit 8b7465dae3
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -269,13 +269,13 @@ public class DisplayUtils {
lastStartIndex = end;
Drawable drawableForChip = DisplayUtils.getDrawableForMentionChipSpan(context,
id,
label,
conversationUser,
type,
chipXmlRes,
null,
viewThemeUtils);
id,
label,
conversationUser,
type,
chipXmlRes,
null,
viewThemeUtils);
mentionChipSpan = new Spans.MentionChipSpan(drawableForChip,
BetterImageSpan.ALIGN_CENTER,
@ -453,18 +453,20 @@ public class DisplayUtils {
}
public static void loadAvatarImage(User user, ImageView avatarImageView, boolean deleteCache) {
String avatarId;
if (!TextUtils.isEmpty(user.getUserId())) {
avatarId = user.getUserId();
} else {
avatarId = user.getUsername();
}
if (avatarId != null) {
if (deleteCache) {
ImageViewExtensionsKt.replaceAvatar(avatarImageView, user, avatarId, true);
if (user != null && avatarImageView != null) {
String avatarId;
if (!TextUtils.isEmpty(user.getUserId())) {
avatarId = user.getUserId();
} else {
ImageViewExtensionsKt.loadAvatar(avatarImageView, user, avatarId, true);
avatarId = user.getUsername();
}
if (avatarId != null) {
if (deleteCache) {
ImageViewExtensionsKt.replaceAvatar(avatarImageView, user, avatarId, true);
} else {
ImageViewExtensionsKt.loadAvatar(avatarImageView, user, avatarId, true);
}
}
}
}