Program: 110354
Project: 110354
Buggy source:
private void reselectTracksInternal() throws ExoPlaybackException {
  if (playingPeriod == null) {
    return;
  }
  Period period=playingPeriod;
  boolean selectionsChangedForReadPeriod=true;
  while (true) {
    if (period == null || !period.prepared) {
      return;
    }
    if (period.selectTracks()) {
      break;
    }
    if (period == readingPeriod) {
      selectionsChangedForReadPeriod=false;
    }
    period=period.nextPeriod;
  }
  if (selectionsChangedForReadPeriod) {
    releasePeriodsFrom(playingPeriod.nextPeriod);
    playingPeriod.nextPeriod=null;
    readingPeriod=playingPeriod;
    loadingPeriod=playingPeriod;
    playingPeriodEndPositionUs=C.UNSET_TIME_US;
    bufferAheadPeriodCount=0;
    boolean recreateStreams=readingPeriod != playingPeriod;
    boolean[] streamResetFlags=playingPeriod.updatePeriodTrackSelection(playbackInfo.positionUs,loadControl,recreateStreams);
    int enabledRendererCount=0;
    boolean[] rendererWasEnabledFlags=new boolean[renderers.length];
    for (int i=0; i < renderers.length; i++) {
      Renderer renderer=renderers[i];
      rendererWasEnabledFlags[i]=renderer.getState() != Renderer.STATE_DISABLED;
      SampleStream sampleStream=playingPeriod.sampleStreams[i];
      if (sampleStream != null) {
        enabledRendererCount++;
      }
      if (rendererWasEnabledFlags[i]) {
        if (sampleStream != renderer.getStream()) {
          if (renderer == rendererMediaClockSource) {
            if (sampleStream == null) {
              standaloneMediaClock.setPositionUs(rendererMediaClock.getPositionUs());
            }
            rendererMediaClock=null;
            rendererMediaClockSource=null;
          }
          ensureStopped(renderer);
          renderer.disable();
        }
 else         if (streamResetFlags[i]) {
          renderer.resetPosition(playbackInfo.positionUs);
        }
      }
    }
    trackSelector.onSelectionActivated(playingPeriod.trackSelectionData);
    enableRenderers(rendererWasEnabledFlags,enabledRendererCount);
  }
 else {
    loadingPeriod=period;
    period=loadingPeriod.nextPeriod;
    while (period != null) {
      period.release();
      period=period.nextPeriod;
      bufferAheadPeriodCount--;
    }
    loadingPeriod.nextPeriod=null;
    long positionUs=Math.max(0,internalPositionUs - loadingPeriod.offsetUs);
    loadingPeriod.updatePeriodTrackSelection(positionUs,loadControl,false);
  }
  maybeContinueLoading();
  updatePlaybackPositions();
  handler.sendEmptyMessage(MSG_DO_SOME_WORK);
}

Fixed version (ground truth):
private void reselectTracksInternal() throws ExoPlaybackException {
  if (playingPeriod == null) {
    return;
  }
  Period period=playingPeriod;
  boolean selectionsChangedForReadPeriod=true;
  while (true) {
    if (period == null || !period.prepared) {
      return;
    }
    if (period.selectTracks()) {
      break;
    }
    if (period == readingPeriod) {
      selectionsChangedForReadPeriod=false;
    }
    period=period.nextPeriod;
  }
  if (selectionsChangedForReadPeriod) {
    releasePeriodsFrom(playingPeriod.nextPeriod);
    playingPeriod.nextPeriod=null;
    readingPeriod=playingPeriod;
    loadingPeriod=playingPeriod;
    playingPeriodEndPositionUs=C.UNSET_TIME_US;
    bufferAheadPeriodCount=0;
    boolean recreateStreams=readingPeriod != playingPeriod;
    boolean[] streamResetFlags=new boolean[renderers.length];
    long positionUs=playingPeriod.updatePeriodTrackSelection(playbackInfo.positionUs,loadControl,recreateStreams,streamResetFlags);
    if (positionUs != playbackInfo.positionUs) {
      playbackInfo.positionUs=positionUs;
      resetInternalPosition(positionUs);
    }
    int enabledRendererCount=0;
    boolean[] rendererWasEnabledFlags=new boolean[renderers.length];
    for (int i=0; i < renderers.length; i++) {
      Renderer renderer=renderers[i];
      rendererWasEnabledFlags[i]=renderer.getState() != Renderer.STATE_DISABLED;
      SampleStream sampleStream=playingPeriod.sampleStreams[i];
      if (sampleStream != null) {
        enabledRendererCount++;
      }
      if (rendererWasEnabledFlags[i]) {
        if (sampleStream != renderer.getStream()) {
          if (renderer == rendererMediaClockSource) {
            if (sampleStream == null) {
              standaloneMediaClock.setPositionUs(rendererMediaClock.getPositionUs());
            }
            rendererMediaClock=null;
            rendererMediaClockSource=null;
          }
          ensureStopped(renderer);
          renderer.disable();
        }
 else         if (streamResetFlags[i]) {
          renderer.resetPosition(playbackInfo.positionUs);
        }
      }
    }
    trackSelector.onSelectionActivated(playingPeriod.trackSelectionData);
    enableRenderers(rendererWasEnabledFlags,enabledRendererCount);
  }
 else {
    loadingPeriod=period;
    period=loadingPeriod.nextPeriod;
    while (period != null) {
      period.release();
      period=period.nextPeriod;
      bufferAheadPeriodCount--;
    }
    loadingPeriod.nextPeriod=null;
    long positionUs=Math.max(0,internalPositionUs - loadingPeriod.offsetUs);
    loadingPeriod.updatePeriodTrackSelection(positionUs,loadControl,false);
  }
  maybeContinueLoading();
  updatePlaybackPositions();
  handler.sendEmptyMessage(MSG_DO_SOME_WORK);
}