Fix nullness warnings in testutil package

PiperOrigin-RevId: 327190676
This commit is contained in:
ibaker 2020-08-18 10:29:40 +01:00 committed by Oliver Woodman
parent 99d245f7a6
commit 54c92080bf
3 changed files with 19 additions and 4 deletions

View File

@ -405,6 +405,21 @@ public final class Util {
return concatenation;
}
/**
* Copies the contents of {@code list} into {@code array}.
*
* <p>{@code list.size()} must be the same as {@code array.length} to ensure the contents can be
* copied into {@code array} without leaving any nulls at the end.
*
* @param list The list to copy items from.
* @param array The array to copy items to.
*/
@SuppressWarnings("nullness:toArray.nullable.elements.not.newarray")
public static <T> void nullSafeListToArray(List<T> list, T[] array) {
Assertions.checkState(list.size() == array.length);
list.toArray(array);
}
/**
* Creates a {@link Handler} on the current {@link Looper} thread.
*

View File

@ -31,6 +31,7 @@ import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.nullness.compatqual.NullableType;
@ -48,7 +49,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
@Nullable private final TransferListener transferListener;
private final long durationUs;
@MonotonicNonNull private Callback callback;
private @MonotonicNonNull Callback callback;
private ChunkSampleStream<FakeChunkSource>[] sampleStreams;
private SequenceableLoader sequenceableLoader;
@ -99,7 +100,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
}
}
sampleStreams = newSampleStreamArray(validStreams.size());
validStreams.toArray(sampleStreams);
Util.nullSafeListToArray(validStreams, sampleStreams);
this.sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
return returnPositionUs;
}

View File

@ -217,8 +217,7 @@ public class FakeDataSource extends BaseDataSource {
* this method.
*/
public final DataSpec[] getAndClearOpenedDataSpecs() {
DataSpec[] dataSpecs = new DataSpec[openedDataSpecs.size()];
openedDataSpecs.toArray(dataSpecs);
DataSpec[] dataSpecs = openedDataSpecs.toArray(new DataSpec[0]);
openedDataSpecs.clear();
return dataSpecs;
}