Suppress rawtypes warning when instantiating generic array

Change FakeAdaptiveMediaPeriod back to this style for consistency.

PiperOrigin-RevId: 284967667
This commit is contained in:
olly 2019-12-11 13:43:31 +00:00 committed by Oliver Woodman
parent 6ebc9f96c8
commit a4a9cc9fd0
3 changed files with 14 additions and 7 deletions

View File

@ -818,7 +818,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
/* initializationData= */ null);
}
@SuppressWarnings("unchecked")
// We won't assign the array to a variable that erases the generic type, and then write into it.
@SuppressWarnings({"unchecked", "rawtypes"})
private static ChunkSampleStream<DashChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length];
}

View File

@ -277,7 +277,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
return new TrackGroupArray(trackGroups);
}
@SuppressWarnings("unchecked")
// We won't assign the array to a variable that erases the generic type, and then write into it.
@SuppressWarnings({"unchecked", "rawtypes"})
private static ChunkSampleStream<SsChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length];
}

View File

@ -45,7 +45,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
private final long durationUs;
private Callback callback;
private List<ChunkSampleStream<FakeChunkSource>> sampleStreams;
private ChunkSampleStream<FakeChunkSource>[] sampleStreams;
private SequenceableLoader sequenceableLoader;
public FakeAdaptiveMediaPeriod(
@ -60,7 +60,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
this.chunkSourceFactory = chunkSourceFactory;
this.transferListener = transferListener;
this.durationUs = durationUs;
this.sampleStreams = new ArrayList<>();
this.sampleStreams = newSampleStreamArray(0);
this.sequenceableLoader = new CompositeSequenceableLoader(new SequenceableLoader[0]);
}
@ -94,9 +94,8 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
validStreams.add((ChunkSampleStream<FakeChunkSource>) stream);
}
}
this.sampleStreams = validStreams;
this.sequenceableLoader =
new CompositeSequenceableLoader(sampleStreams.toArray(new SequenceableLoader[0]));
this.sampleStreams = validStreams.toArray(newSampleStreamArray(validStreams.size()));
this.sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
return returnPositionUs;
}
@ -166,4 +165,10 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
public void onContinueLoadingRequested(ChunkSampleStream<FakeChunkSource> source) {
callback.onContinueLoadingRequested(this);
}
// We won't assign the array to a variable that erases the generic type, and then write into it.
@SuppressWarnings({"unchecked", "rawtypes"})
private static ChunkSampleStream<FakeChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length];
}
}