From 3738e309495ae7de404268b20a85b9ebe87cb4d7 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 9 Apr 2024 20:18:21 +0200 Subject: [PATCH] Fix NPE when avatarUrl is empty --- .../newpipe/database/subscription/SubscriptionEntity.java | 4 +++- .../org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt | 2 +- .../schabi/newpipe/local/subscription/SubscriptionManager.kt | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/database/subscription/SubscriptionEntity.java b/app/src/main/java/org/schabi/newpipe/database/subscription/SubscriptionEntity.java index a61a22a84..df5a3067a 100644 --- a/app/src/main/java/org/schabi/newpipe/database/subscription/SubscriptionEntity.java +++ b/app/src/main/java/org/schabi/newpipe/database/subscription/SubscriptionEntity.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.database.subscription; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.Ignore; @@ -95,11 +96,12 @@ public class SubscriptionEntity { this.name = name; } + @Nullable public String getAvatarUrl() { return avatarUrl; } - public void setAvatarUrl(final String avatarUrl) { + public void setAvatarUrl(@Nullable final String avatarUrl) { this.avatarUrl = avatarUrl; } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt index 84cd8ed59..b44eec353 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt @@ -18,7 +18,7 @@ data class FeedUpdateInfo( @NotificationMode val notificationMode: Int, val name: String, - val avatarUrl: String, + val avatarUrl: String?, val url: String, val serviceId: Int, // description and subscriberCount are null if the constructor info is from the fast feed method diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt index 488d8b3d2..474add4f4 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt @@ -100,7 +100,9 @@ class SubscriptionManager(context: Context) { val subscriptionEntity = subscriptionTable.getSubscription(info.uid) subscriptionEntity.name = info.name - subscriptionEntity.avatarUrl = info.avatarUrl + + // some services do not provide an avatar URL + info.avatarUrl?.let { subscriptionEntity.avatarUrl = it } // these two fields are null if the feed info was fetched using the fast feed method info.description?.let { subscriptionEntity.description = it }