1
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-11-16 13:53:53 +01:00

Fix NPE and add some @Nullables

Fix NullPointerException in PlayerHolder.getQueueSize() and add `@Nullable` here and there so that the linter reports risks of NPEs
This commit is contained in:
Stypox 2022-01-25 17:37:15 +01:00
parent ac53196dcc
commit 5108d75682
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 11 additions and 5 deletions

View File

@ -260,7 +260,8 @@ public final class Player implements
// Playback
//////////////////////////////////////////////////////////////////////////*/
private PlayQueue playQueue;
// play queue might be null e.g. while player is starting
@Nullable private PlayQueue playQueue;
private PlayQueueAdapter playQueueAdapter;
private StreamSegmentAdapter segmentAdapter;
@ -4202,6 +4203,7 @@ public final class Player implements
}
@Nullable
public PlayQueue getPlayQueue() {
return playQueue;
}

View File

@ -38,12 +38,12 @@ public final class PlayerHolder {
private static final boolean DEBUG = MainActivity.DEBUG;
private static final String TAG = PlayerHolder.class.getSimpleName();
private PlayerServiceExtendedEventListener listener;
@Nullable private PlayerServiceExtendedEventListener listener;
private final PlayerServiceConnection serviceConnection = new PlayerServiceConnection();
private boolean bound;
private MainPlayer playerService;
private Player player;
@Nullable private MainPlayer playerService;
@Nullable private Player player;
/**
* Returns the current {@link MainPlayer.PlayerType} of the {@link MainPlayer} service,
@ -75,7 +75,11 @@ public final class PlayerHolder {
}
public int getQueueSize() {
return isPlayerOpen() ? player.getPlayQueue().size() : 0;
if (player == null || player.getPlayQueue() == null) {
// player play queue might be null e.g. while player is starting
return 0;
}
return player.getPlayQueue().size();
}
public void setListener(@Nullable final PlayerServiceExtendedEventListener newListener) {