Commit 54c92080 by ibaker Committed by Oliver Woodman

Fix nullness warnings in testutil package

PiperOrigin-RevId: 327190676
parent 99d245f7
......@@ -406,6 +406,21 @@ public final class Util {
}
/**
* 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.
*
* @throws IllegalStateException If the current thread doesn't have a {@link Looper}.
......
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment