Program: 110285
Project: 110285
Buggy source:
@Override public long selectTracks(TrackSelection[] selections,boolean[] mayRetainStreamFlags,SampleStream[] streams,boolean[] streamResetFlags,long positionUs){
  Assertions.checkState(prepared);
  int oldEnabledTrackCount=enabledTrackCount;
  for (int i=0; i < selections.length; i++) {
    if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
      int track=((SampleStreamImpl)streams[i]).track;
      Assertions.checkState(trackEnabledStates[track]);
      enabledTrackCount--;
      trackEnabledStates[track]=false;
      streams[i]=null;
    }
  }
  boolean seekRequired=seenFirstTrackSelection ? oldEnabledTrackCount == 0 : positionUs != 0;
  for (int i=0; i < selections.length; i++) {
    if (streams[i] == null && selections[i] != null) {
      TrackSelection selection=selections[i];
      Assertions.checkState(selection.length() == 1);
      Assertions.checkState(selection.getIndexInTrackGroup(0) == 0);
      int track=tracks.indexOf(selection.getTrackGroup());
      Assertions.checkState(!trackEnabledStates[track]);
      enabledTrackCount++;
      trackEnabledStates[track]=true;
      streams[i]=new SampleStreamImpl(track);
      streamResetFlags[i]=true;
      if (!seekRequired) {
        SampleQueue sampleQueue=sampleQueues[i];
        sampleQueue.rewind();
        seekRequired=!sampleQueue.advanceTo(positionUs,true,true) && sampleQueue.getReadIndex() != 0;
      }
    }
  }
  if (enabledTrackCount == 0) {
    notifyReset=false;
    if (loader.isLoading()) {
      loader.cancelLoading();
    }
  }
 else   if (seekRequired) {
    positionUs=seekToUs(positionUs);
    for (int i=0; i < streams.length; i++) {
      if (streams[i] != null) {
        streamResetFlags[i]=true;
      }
    }
  }
  seenFirstTrackSelection=true;
  return positionUs;
}

Fixed version (ground truth):
@Override public long selectTracks(TrackSelection[] selections,boolean[] mayRetainStreamFlags,SampleStream[] streams,boolean[] streamResetFlags,long positionUs){
  Assertions.checkState(prepared);
  int oldEnabledTrackCount=enabledTrackCount;
  for (int i=0; i < selections.length; i++) {
    if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
      int track=((SampleStreamImpl)streams[i]).track;
      Assertions.checkState(trackEnabledStates[track]);
      enabledTrackCount--;
      trackEnabledStates[track]=false;
      streams[i]=null;
    }
  }
  boolean seekRequired=seenFirstTrackSelection ? oldEnabledTrackCount == 0 : positionUs != 0;
  for (int i=0; i < selections.length; i++) {
    if (streams[i] == null && selections[i] != null) {
      TrackSelection selection=selections[i];
      Assertions.checkState(selection.length() == 1);
      Assertions.checkState(selection.getIndexInTrackGroup(0) == 0);
      int track=tracks.indexOf(selection.getTrackGroup());
      Assertions.checkState(!trackEnabledStates[track]);
      enabledTrackCount++;
      trackEnabledStates[track]=true;
      streams[i]=new SampleStreamImpl(track);
      streamResetFlags[i]=true;
      if (!seekRequired) {
        SampleQueue sampleQueue=sampleQueues[track];
        sampleQueue.rewind();
        seekRequired=!sampleQueue.advanceTo(positionUs,true,true) && sampleQueue.getReadIndex() != 0;
      }
    }
  }
  if (enabledTrackCount == 0) {
    notifyReset=false;
    if (loader.isLoading()) {
      loader.cancelLoading();
    }
  }
 else   if (seekRequired) {
    positionUs=seekToUs(positionUs);
    for (int i=0; i < streams.length; i++) {
      if (streams[i] != null) {
        streamResetFlags[i]=true;
      }
    }
  }
  seenFirstTrackSelection=true;
  return positionUs;
}