#2966 RxJava2 null - case the underlying method may return null, but

should never happen in the code path, e.g.,
 return the current FeedItem in ItemFragment UI.
Mark underlying method as @Nullable, and let observer's existing
 onError() to handle null case

Rx observer : underlying sources marked as @Nullable
 ItemFragment.load : .loadInBackground
 MediaplayerActivity.checkFavorite : DBReader.getFeedItem
 ItemDescriptionFragment.onViewCreated : DBReader.getFeedItem
 ItemlistFragment.loadItems : .loadData
This commit is contained in:
orionlee 2019-01-10 12:11:55 -08:00
parent 0472bb9237
commit 1655d234af
3 changed files with 10 additions and 7 deletions

View File

@ -588,6 +588,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@Nullable
private FeedItem loadInBackground() {
FeedItem feedItem = DBReader.getFeedItem(feedItems[feedItemPos]);
if (feedItem != null) {

View File

@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.LightingColorFilter;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
@ -25,7 +26,6 @@ import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.widget.IconTextView;
@ -618,16 +618,15 @@ public class ItemlistFragment extends ListFragment {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
if (result != null) {
feed = result;
itemsLoaded = true;
if (viewsCreated) {
onFragmentLoaded();
}
feed = result;
itemsLoaded = true;
if (viewsCreated) {
onFragmentLoaded();
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@Nullable
private Feed loadData() {
Feed feed = DBReader.getFeed(feedID);
DBReader.loadAdditionalFeedItemListData(feed.getItems());

View File

@ -604,6 +604,7 @@ public final class DBReader {
}
}
@Nullable
private static FeedItem getFeedItem(final long itemId, PodDBAdapter adapter) {
Log.d(TAG, "Loading feeditem with id " + itemId);
@ -637,6 +638,7 @@ public final class DBReader {
* @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
* as well as chapter marks of the FeedItem will also be loaded from the database.
*/
@Nullable
public static FeedItem getFeedItem(final long itemId) {
Log.d(TAG, "getFeedItem() called with: " + "itemId = [" + itemId + "]");
@ -649,6 +651,7 @@ public final class DBReader {
}
}
@Nullable
private static FeedItem getFeedItem(final String podcastUrl, final String episodeUrl, PodDBAdapter adapter) {
Log.d(TAG, "Loading feeditem with podcast url " + podcastUrl + " and episode url " + episodeUrl);
Cursor cursor = null;