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); /* 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) { private static ChunkSampleStream<DashChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length]; return new ChunkSampleStream[length];
} }

View File

@ -277,7 +277,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
return new TrackGroupArray(trackGroups); 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) { private static ChunkSampleStream<SsChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length]; return new ChunkSampleStream[length];
} }

View File

@ -45,7 +45,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
private final long durationUs; private final long durationUs;
private Callback callback; private Callback callback;
private List<ChunkSampleStream<FakeChunkSource>> sampleStreams; private ChunkSampleStream<FakeChunkSource>[] sampleStreams;
private SequenceableLoader sequenceableLoader; private SequenceableLoader sequenceableLoader;
public FakeAdaptiveMediaPeriod( public FakeAdaptiveMediaPeriod(
@ -60,7 +60,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
this.chunkSourceFactory = chunkSourceFactory; this.chunkSourceFactory = chunkSourceFactory;
this.transferListener = transferListener; this.transferListener = transferListener;
this.durationUs = durationUs; this.durationUs = durationUs;
this.sampleStreams = new ArrayList<>(); this.sampleStreams = newSampleStreamArray(0);
this.sequenceableLoader = new CompositeSequenceableLoader(new SequenceableLoader[0]); this.sequenceableLoader = new CompositeSequenceableLoader(new SequenceableLoader[0]);
} }
@ -94,9 +94,8 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
validStreams.add((ChunkSampleStream<FakeChunkSource>) stream); validStreams.add((ChunkSampleStream<FakeChunkSource>) stream);
} }
} }
this.sampleStreams = validStreams; this.sampleStreams = validStreams.toArray(newSampleStreamArray(validStreams.size()));
this.sequenceableLoader = this.sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
new CompositeSequenceableLoader(sampleStreams.toArray(new SequenceableLoader[0]));
return returnPositionUs; return returnPositionUs;
} }
@ -166,4 +165,10 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
public void onContinueLoadingRequested(ChunkSampleStream<FakeChunkSource> source) { public void onContinueLoadingRequested(ChunkSampleStream<FakeChunkSource> source) {
callback.onContinueLoadingRequested(this); 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];
}
} }