Program: 110439
Project: 110439
Buggy source:
/** 
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 * @param playlistUrl The playlist URL.
 * @param playlist The hls playlist.
 * @param bandwidthMeter provides an estimate of the currently available bandwidth.
 * @param variantIndices If {@code playlist} is a {@link HlsMasterPlaylist}, the subset of variant indices to consider, or null to consider all of the variants. For other playlist types this parameter is ignored.
 * @param adaptiveMode The mode for switching from one variant to another. One of{@link #ADAPTIVE_MODE_NONE},   {@link #ADAPTIVE_MODE_ABRUPT} and{@link #ADAPTIVE_MODE_SPLICE}.
 * @param minBufferDurationToSwitchUpMs The minimum duration of media that needs to be bufferedfor a switch to a higher quality variant to be considered.
 * @param maxBufferDurationToSwitchDownMs The maximum duration of media that needs to be bufferedfor a switch to a lower quality variant to be considered.
 * @param audioCapabilities The audio capabilities for playback on this device, or {@code null} ifthe default capabilities should be assumed.
 */
public HlsChunkSource(DataSource dataSource,String playlistUrl,HlsPlaylist playlist,BandwidthMeter bandwidthMeter,int[] variantIndices,int adaptiveMode,long minBufferDurationToSwitchUpMs,long maxBufferDurationToSwitchDownMs,AudioCapabilities audioCapabilities){
  this.dataSource=dataSource;
  this.bandwidthMeter=bandwidthMeter;
  this.adaptiveMode=adaptiveMode;
  this.audioCapabilities=audioCapabilities;
  minBufferDurationToSwitchUpUs=minBufferDurationToSwitchUpMs * 1000;
  maxBufferDurationToSwitchDownUs=maxBufferDurationToSwitchDownMs * 1000;
  baseUri=playlist.baseUri;
  playlistParser=new HlsPlaylistParser();
  if (playlist.type == HlsPlaylist.TYPE_MEDIA) {
    variants=new Variant[]{new Variant(0,playlistUrl,0,null,-1,-1)};
    variantPlaylists=new HlsMediaPlaylist[]{(HlsMediaPlaylist)playlist};
    variantLastPlaylistLoadTimesMs=new long[1];
    variantBlacklistTimes=new long[1];
    maxWidth=-1;
    maxHeight=-1;
  }
 else {
    List<Variant> masterPlaylistVariants=((HlsMasterPlaylist)playlist).variants;
    variants=buildOrderedVariants(masterPlaylistVariants,variantIndices);
    variantPlaylists=new HlsMediaPlaylist[variants.length];
    variantLastPlaylistLoadTimesMs=new long[variants.length];
    variantBlacklistTimes=new long[variants.length];
    int maxWidth=-1;
    int maxHeight=-1;
    int minOriginalVariantIndex=Integer.MAX_VALUE;
    for (int i=0; i < variants.length; i++) {
      int originalVariantIndex=masterPlaylistVariants.indexOf(variants[i]);
      if (originalVariantIndex < minOriginalVariantIndex) {
        minOriginalVariantIndex=originalVariantIndex;
        selectedVariantIndex=i;
      }
      Format variantFormat=variants[i].format;
      maxWidth=Math.max(variantFormat.width,maxWidth);
      maxHeight=Math.max(variantFormat.height,maxHeight);
    }
    if (variants.length <= 1 || adaptiveMode == ADAPTIVE_MODE_NONE) {
      this.maxWidth=-1;
      this.maxHeight=-1;
    }
 else {
      this.maxWidth=maxWidth > 0 ? maxWidth : 1920;
      this.maxHeight=maxHeight > 0 ? maxHeight : 1080;
    }
  }
}

Fixed version (ground truth):
/** 
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 * @param playlistUrl The playlist URL.
 * @param playlist The hls playlist.
 * @param bandwidthMeter provides an estimate of the currently available bandwidth.
 * @param variantIndices If {@code playlist} is a {@link HlsMasterPlaylist}, the subset of variant indices to consider, or null to consider all of the variants. For other playlist types this parameter is ignored.
 * @param adaptiveMode The mode for switching from one variant to another. One of{@link #ADAPTIVE_MODE_NONE},   {@link #ADAPTIVE_MODE_ABRUPT} and{@link #ADAPTIVE_MODE_SPLICE}.
 * @param minBufferDurationToSwitchUpMs The minimum duration of media that needs to be bufferedfor a switch to a higher quality variant to be considered.
 * @param maxBufferDurationToSwitchDownMs The maximum duration of media that needs to be bufferedfor a switch to a lower quality variant to be considered.
 * @param audioCapabilities The audio capabilities for playback on this device, or {@code null} ifthe default capabilities should be assumed.
 */
public HlsChunkSource(DataSource dataSource,String playlistUrl,HlsPlaylist playlist,BandwidthMeter bandwidthMeter,int[] variantIndices,int adaptiveMode,long minBufferDurationToSwitchUpMs,long maxBufferDurationToSwitchDownMs,AudioCapabilities audioCapabilities){
  this.dataSource=dataSource;
  this.bandwidthMeter=bandwidthMeter;
  this.adaptiveMode=adaptiveMode;
  this.audioCapabilities=audioCapabilities;
  minBufferDurationToSwitchUpUs=minBufferDurationToSwitchUpMs * 1000;
  maxBufferDurationToSwitchDownUs=maxBufferDurationToSwitchDownMs * 1000;
  baseUri=playlist.baseUri;
  playlistParser=new HlsPlaylistParser();
  if (playlist.type == HlsPlaylist.TYPE_MEDIA) {
    variants=new Variant[]{new Variant(0,playlistUrl,0,null,-1,-1)};
    variantPlaylists=new HlsMediaPlaylist[1];
    variantLastPlaylistLoadTimesMs=new long[1];
    variantBlacklistTimes=new long[1];
    setMediaPlaylist(0,(HlsMediaPlaylist)playlist);
    maxWidth=-1;
    maxHeight=-1;
  }
 else {
    List<Variant> masterPlaylistVariants=((HlsMasterPlaylist)playlist).variants;
    variants=buildOrderedVariants(masterPlaylistVariants,variantIndices);
    variantPlaylists=new HlsMediaPlaylist[variants.length];
    variantLastPlaylistLoadTimesMs=new long[variants.length];
    variantBlacklistTimes=new long[variants.length];
    int maxWidth=-1;
    int maxHeight=-1;
    int minOriginalVariantIndex=Integer.MAX_VALUE;
    for (int i=0; i < variants.length; i++) {
      int originalVariantIndex=masterPlaylistVariants.indexOf(variants[i]);
      if (originalVariantIndex < minOriginalVariantIndex) {
        minOriginalVariantIndex=originalVariantIndex;
        selectedVariantIndex=i;
      }
      Format variantFormat=variants[i].format;
      maxWidth=Math.max(variantFormat.width,maxWidth);
      maxHeight=Math.max(variantFormat.height,maxHeight);
    }
    if (variants.length <= 1 || adaptiveMode == ADAPTIVE_MODE_NONE) {
      this.maxWidth=-1;
      this.maxHeight=-1;
    }
 else {
      this.maxWidth=maxWidth > 0 ? maxWidth : 1920;
      this.maxHeight=maxHeight > 0 ? maxHeight : 1080;
    }
  }
}