From 52d47aa244f677bf32ba8c3b7c284f61e44b66db Mon Sep 17 00:00:00 2001 From: olly Date: Fri, 20 Jan 2017 11:17:37 -0800 Subject: [PATCH] Fix possible track selection NPE If no tracks are selected at the start of playback, TrackSelectorResult isEquivalent(null) returned true, meaning we were keeping the old result (i.e. null), which we then tried to de-reference. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=145105702 --- .../trackselection/TrackSelectorResult.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelectorResult.java b/library/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelectorResult.java index 390b77391c..5cdb157570 100644 --- a/library/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelectorResult.java +++ b/library/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelectorResult.java @@ -61,10 +61,14 @@ public final class TrackSelectorResult { /** * Returns whether this result is equivalent to {@code other} for all renderers. * - * @param other The other {@link TrackSelectorResult}. May be null. + * @param other The other {@link TrackSelectorResult}. May be null, in which case {@code false} + * will be returned in all cases. * @return Whether this result is equivalent to {@code other} for all renderers. */ public boolean isEquivalent(TrackSelectorResult other) { + if (other == null) { + return false; + } for (int i = 0; i < selections.length; i++) { if (!isEquivalent(other, i)) { return false; @@ -78,13 +82,14 @@ public final class TrackSelectorResult { * The results are equivalent if they have equal track selections and configurations for the * renderer. * - * @param other The other {@link TrackSelectorResult}. May be null. + * @param other The other {@link TrackSelectorResult}. May be null, in which case {@code false} + * will be returned in all cases. * @param index The renderer index to check for equivalence. * @return Whether this result is equivalent to {@code other} for all renderers. */ public boolean isEquivalent(TrackSelectorResult other, int index) { if (other == null) { - return selections.get(index) == null && rendererConfigurations[index] == null; + return false; } return Util.areEqual(selections.get(index), other.selections.get(index)) && Util.areEqual(rendererConfigurations[index], other.rendererConfigurations[index]);