nus-yam/ex-repair huggingface dataset:
Program: 110182
Project: 110182
Buggy source:
/** 
 * Initializes the download, returning a list of   {@link Segment}s that need to be downloaded. 
 */
private List<Segment> initDownload() throws IOException, InterruptedException {
  M manifest=getManifest(dataSource,manifestUri);
  if (!streamKeys.isEmpty()) {
    manifest=manifest.copy(streamKeys);
  }
  List<Segment> segments=getSegments(dataSource,manifest,false);
  CachingCounters cachingCounters=new CachingCounters();
  totalSegments=segments.size();
  downloadedSegments=0;
  downloadedBytes=0;
  for (int i=segments.size() - 1; i >= 0; i--) {
    Segment segment=segments.get(i);
    CacheUtil.getCached(segment.dataSpec,cache,cachingCounters);
    downloadedBytes+=cachingCounters.alreadyCachedBytes;
    if (cachingCounters.alreadyCachedBytes == cachingCounters.contentLength) {
      downloadedSegments++;
      segments.remove(i);
    }
  }
  return segments;
}

Fixed version (ground truth):
/** 
 * Initializes the download, returning a list of   {@link Segment}s that need to be downloaded. 
 */
@SuppressWarnings("String_Node_Str") private List<Segment> initDownload() throws IOException, InterruptedException {
  M manifest=getManifest(dataSource,manifestUri);
  if (!streamKeys.isEmpty()) {
    manifest=manifest.copy(streamKeys);
  }
  List<Segment> segments=getSegments(dataSource,manifest,false);
  CachingCounters cachingCounters=new CachingCounters();
  totalSegments=segments.size();
  downloadedSegments=0;
  downloadedBytes=0;
  for (int i=segments.size() - 1; i >= 0; i--) {
    Segment segment=segments.get(i);
    CacheUtil.getCached(segment.dataSpec,cache,cachingCounters);
    downloadedBytes+=cachingCounters.alreadyCachedBytes;
    if (cachingCounters.alreadyCachedBytes == cachingCounters.contentLength) {
      downloadedSegments++;
      segments.remove(i);
    }
  }
  return segments;
}
Program: 110183
Project: 110183
Buggy source:
/** 
 * Returns the index of the track with the given format in the group.
 * @param format The format.
 * @return The index of the track, or {@link C#INDEX_UNSET} if no such track exists.
 */
public int indexOf(Format format){
  for (int i=0; i < formats.length; i++) {
    if (format == formats[i]) {
      return i;
    }
  }
  return C.INDEX_UNSET;
}

Fixed version (ground truth):
/** 
 * Returns the index of the track with the given format in the group. The format is located by identity so, for example,   {@code group.indexOf(group.getFormat(index)) == index} even ifmultiple tracks have formats that contain the same values.
 * @param format The format.
 * @return The index of the track, or {@link C#INDEX_UNSET} if no such track exists.
 */
@SuppressWarnings("String_Node_Str") public int indexOf(Format format){
  for (int i=0; i < formats.length; i++) {
    if (format == formats[i]) {
      return i;
    }
  }
  return C.INDEX_UNSET;
}
Program: 110184
Project: 110184
Buggy source:
@Override protected void decode(SubtitleInputBuffer inputBuffer){
  ccData.reset(inputBuffer.data.array(),inputBuffer.data.limit());
  while (ccData.bytesLeft() >= 3) {
    int ccTypeAndValid=(ccData.readUnsignedByte() & 0x07);
    int ccType=ccTypeAndValid & (DTVCC_PACKET_DATA | DTVCC_PACKET_START);
    boolean ccValid=(ccTypeAndValid & CC_VALID_FLAG) == CC_VALID_FLAG;
    byte ccData1=(byte)ccData.readUnsignedByte();
    byte ccData2=(byte)ccData.readUnsignedByte();
    if (ccType != DTVCC_PACKET_DATA && ccType != DTVCC_PACKET_START) {
      continue;
    }
    if (!ccValid) {
      continue;
    }
    if (ccType == DTVCC_PACKET_START) {
      finalizeCurrentPacket();
      int sequenceNumber=(ccData1 & 0xC0) >> 6;
      int packetSize=ccData1 & 0x3F;
      if (packetSize == 0) {
        packetSize=64;
      }
      currentDtvCcPacket=new DtvCcPacket(sequenceNumber,packetSize);
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++]=ccData2;
    }
 else {
      Assertions.checkArgument(ccType == DTVCC_PACKET_DATA);
      if (currentDtvCcPacket == null) {
        Log.e(TAG,"String_Node_Str");
        continue;
      }
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++]=ccData1;
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++]=ccData2;
    }
    if (currentDtvCcPacket.currentIndex == (currentDtvCcPacket.packetSize * 2 - 1)) {
      finalizeCurrentPacket();
    }
  }
}

Fixed version (ground truth):
@Override protected void decode(SubtitleInputBuffer inputBuffer){
  @SuppressWarnings("String_Node_Str") byte[] inputBufferData=inputBuffer.data.array();
  ccData.reset(inputBufferData,inputBuffer.data.limit());
  while (ccData.bytesLeft() >= 3) {
    int ccTypeAndValid=(ccData.readUnsignedByte() & 0x07);
    int ccType=ccTypeAndValid & (DTVCC_PACKET_DATA | DTVCC_PACKET_START);
    boolean ccValid=(ccTypeAndValid & CC_VALID_FLAG) == CC_VALID_FLAG;
    byte ccData1=(byte)ccData.readUnsignedByte();
    byte ccData2=(byte)ccData.readUnsignedByte();
    if (ccType != DTVCC_PACKET_DATA && ccType != DTVCC_PACKET_START) {
      continue;
    }
    if (!ccValid) {
      continue;
    }
    if (ccType == DTVCC_PACKET_START) {
      finalizeCurrentPacket();
      int sequenceNumber=(ccData1 & 0xC0) >> 6;
      int packetSize=ccData1 & 0x3F;
      if (packetSize == 0) {
        packetSize=64;
      }
      currentDtvCcPacket=new DtvCcPacket(sequenceNumber,packetSize);
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++]=ccData2;
    }
 else {
      Assertions.checkArgument(ccType == DTVCC_PACKET_DATA);
      if (currentDtvCcPacket == null) {
        Log.e(TAG,"String_Node_Str");
        continue;
      }
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++]=ccData1;
      currentDtvCcPacket.packetData[currentDtvCcPacket.currentIndex++]=ccData2;
    }
    if (currentDtvCcPacket.currentIndex == (currentDtvCcPacket.packetSize * 2 - 1)) {
      finalizeCurrentPacket();
    }
  }
}
Program: 110185
Project: 110185
Buggy source:
public CueBuilder(){
  rolledUpCaptions=new LinkedList<>();
  captionStringBuilder=new SpannableStringBuilder();
  reset();
}

Fixed version (ground truth):
public CueBuilder(){
  rolledUpCaptions=new ArrayList<>();
  captionStringBuilder=new SpannableStringBuilder();
  reset();
}
Program: 110186
Project: 110186
Buggy source:
public CeaDecoder(){
  availableInputBuffers=new LinkedList<>();
  for (int i=0; i < NUM_INPUT_BUFFERS; i++) {
    availableInputBuffers.add(new CeaInputBuffer());
  }
  availableOutputBuffers=new LinkedList<>();
  for (int i=0; i < NUM_OUTPUT_BUFFERS; i++) {
    availableOutputBuffers.add(new CeaOutputBuffer());
  }
  queuedInputBuffers=new PriorityQueue<>();
}

Fixed version (ground truth):
public CeaDecoder(){
  availableInputBuffers=new ArrayDeque<>();
  for (int i=0; i < NUM_INPUT_BUFFERS; i++) {
    availableInputBuffers.add(new CeaInputBuffer());
  }
  availableOutputBuffers=new ArrayDeque<>();
  for (int i=0; i < NUM_OUTPUT_BUFFERS; i++) {
    availableOutputBuffers.add(new CeaOutputBuffer());
  }
  queuedInputBuffers=new PriorityQueue<>();
}
Program: 110187
Project: 110187
Buggy source:
/** 
 * @param initializationData Optional initialization data for the decoder. If not null or empty,the initialization data must consist of two byte arrays. The first must contain an SSA format line. The second must contain an SSA header that will be assumed common to all samples.
 */
public SsaDecoder(List<byte[]> initializationData){
  super("String_Node_Str");
  if (initializationData != null && !initializationData.isEmpty()) {
    haveInitializationData=true;
    String formatLine=new String(initializationData.get(0));
    Assertions.checkArgument(formatLine.startsWith(FORMAT_LINE_PREFIX));
    parseFormatLine(formatLine);
    parseHeader(new ParsableByteArray(initializationData.get(1)));
  }
 else {
    haveInitializationData=false;
  }
}

Fixed version (ground truth):
/** 
 * @param initializationData Optional initialization data for the decoder. If not null or empty,the initialization data must consist of two byte arrays. The first must contain an SSA format line. The second must contain an SSA header that will be assumed common to all samples.
 */
public SsaDecoder(List<byte[]> initializationData){
  super("String_Node_Str");
  if (initializationData != null && !initializationData.isEmpty()) {
    haveInitializationData=true;
    String formatLine=Util.fromUtf8Bytes(initializationData.get(0));
    Assertions.checkArgument(formatLine.startsWith(FORMAT_LINE_PREFIX));
    parseFormatLine(formatLine);
    parseHeader(new ParsableByteArray(initializationData.get(1)));
  }
 else {
    haveInitializationData=false;
  }
}
Program: 110188
Project: 110188
Buggy source:
@Override public void addTextOutput(TextOutput listener){
  listener.onCues(currentCues);
  textOutputs.add(listener);
}

Fixed version (ground truth):
@Override public void addTextOutput(TextOutput listener){
  if (currentCues != null) {
    listener.onCues(currentCues);
  }
  textOutputs.add(listener);
}
Program: 110189
Project: 110189
Buggy source:
@Override public void close() throws IOException {
  cipherInputStream=null;
  upstream.close();
}

Fixed version (ground truth):
@Override public void close() throws IOException {
  if (cipherInputStream != null) {
    cipherInputStream=null;
    upstream.close();
  }
}
Program: 110190
Project: 110190
Buggy source:
@Override public long open(DataSpec dataSpec) throws IOException {
  Cipher cipher;
  try {
    cipher=Cipher.getInstance("String_Node_Str");
  }
 catch (  NoSuchAlgorithmException|NoSuchPaddingException e) {
    throw new RuntimeException(e);
  }
  Key cipherKey=new SecretKeySpec(encryptionKey,"String_Node_Str");
  AlgorithmParameterSpec cipherIV=new IvParameterSpec(encryptionIv);
  try {
    cipher.init(Cipher.DECRYPT_MODE,cipherKey,cipherIV);
  }
 catch (  InvalidKeyException|InvalidAlgorithmParameterException e) {
    throw new RuntimeException(e);
  }
  cipherInputStream=new CipherInputStream(new DataSourceInputStream(upstream,dataSpec),cipher);
  return C.LENGTH_UNSET;
}

Fixed version (ground truth):
@Override public long open(DataSpec dataSpec) throws IOException {
  Cipher cipher;
  try {
    cipher=Cipher.getInstance("String_Node_Str");
  }
 catch (  NoSuchAlgorithmException|NoSuchPaddingException e) {
    throw new RuntimeException(e);
  }
  Key cipherKey=new SecretKeySpec(encryptionKey,"String_Node_Str");
  AlgorithmParameterSpec cipherIV=new IvParameterSpec(encryptionIv);
  try {
    cipher.init(Cipher.DECRYPT_MODE,cipherKey,cipherIV);
  }
 catch (  InvalidKeyException|InvalidAlgorithmParameterException e) {
    throw new RuntimeException(e);
  }
  DataSourceInputStream inputStream=new DataSourceInputStream(upstream,dataSpec);
  cipherInputStream=new CipherInputStream(inputStream,cipher);
  inputStream.open();
  return C.LENGTH_UNSET;
}
Program: 110191
Project: 110191
Buggy source:
/** 
 * Returns the track groups for the given period. Must not be called until after preparation completes.
 * @param periodIndex The period index.
 * @return The track groups for the period. May be {@link TrackGroupArray.EMPTY} for single streamcontent.
 */
public abstract TrackGroupArray getTrackGroups(int periodIndex);

Fixed version (ground truth):
/** 
 * Returns the track groups for the given period. Must not be called until after preparation completes.
 * @param periodIndex The period index.
 * @return The track groups for the period. May be {@link TrackGroupArray#EMPTY} for single streamcontent.
 */
public abstract TrackGroupArray getTrackGroups(int periodIndex);
Program: 110192
Project: 110192
Buggy source:
/** 
 * @param initialValues The {@link Parameters} from which the initial values of the builder areobtained.
 */
private ParametersBuilder(Parameters initialValues){
  selectionOverrides=initialValues.selectionOverrides.clone();
  rendererDisabledFlags=initialValues.rendererDisabledFlags.clone();
  preferredAudioLanguage=initialValues.preferredAudioLanguage;
  preferredTextLanguage=initialValues.preferredTextLanguage;
  selectUndeterminedTextLanguage=initialValues.selectUndeterminedTextLanguage;
  disabledTextTrackSelectionFlags=initialValues.disabledTextTrackSelectionFlags;
  forceLowestBitrate=initialValues.forceLowestBitrate;
  allowMixedMimeAdaptiveness=initialValues.allowMixedMimeAdaptiveness;
  allowNonSeamlessAdaptiveness=initialValues.allowNonSeamlessAdaptiveness;
  maxVideoWidth=initialValues.maxVideoWidth;
  maxVideoHeight=initialValues.maxVideoHeight;
  maxVideoBitrate=initialValues.maxVideoBitrate;
  exceedVideoConstraintsIfNecessary=initialValues.exceedVideoConstraintsIfNecessary;
  exceedRendererCapabilitiesIfNecessary=initialValues.exceedRendererCapabilitiesIfNecessary;
  viewportWidth=initialValues.viewportWidth;
  viewportHeight=initialValues.viewportHeight;
  viewportOrientationMayChange=initialValues.viewportOrientationMayChange;
  tunnelingAudioSessionId=initialValues.tunnelingAudioSessionId;
}

Fixed version (ground truth):
/** 
 * @param initialValues The {@link Parameters} from which the initial values of the builder areobtained.
 */
private ParametersBuilder(Parameters initialValues){
  selectionOverrides=cloneSelectionOverrides(initialValues.selectionOverrides);
  rendererDisabledFlags=initialValues.rendererDisabledFlags.clone();
  preferredAudioLanguage=initialValues.preferredAudioLanguage;
  preferredTextLanguage=initialValues.preferredTextLanguage;
  selectUndeterminedTextLanguage=initialValues.selectUndeterminedTextLanguage;
  disabledTextTrackSelectionFlags=initialValues.disabledTextTrackSelectionFlags;
  forceLowestBitrate=initialValues.forceLowestBitrate;
  allowMixedMimeAdaptiveness=initialValues.allowMixedMimeAdaptiveness;
  allowNonSeamlessAdaptiveness=initialValues.allowNonSeamlessAdaptiveness;
  maxVideoWidth=initialValues.maxVideoWidth;
  maxVideoHeight=initialValues.maxVideoHeight;
  maxVideoBitrate=initialValues.maxVideoBitrate;
  exceedVideoConstraintsIfNecessary=initialValues.exceedVideoConstraintsIfNecessary;
  exceedRendererCapabilitiesIfNecessary=initialValues.exceedRendererCapabilitiesIfNecessary;
  viewportWidth=initialValues.viewportWidth;
  viewportHeight=initialValues.viewportHeight;
  viewportOrientationMayChange=initialValues.viewportOrientationMayChange;
  tunnelingAudioSessionId=initialValues.tunnelingAudioSessionId;
}
Program: 110193
Project: 110193
Buggy source:
@Override public void onRequestPermissionsResult(int requestCode,@NonNull String[] permissions,@NonNull int[] grantResults){
  if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    initializePlayer();
  }
 else {
    showToast(R.string.storage_permission_denied);
    finish();
  }
}

Fixed version (ground truth):
@Override public void onRequestPermissionsResult(int requestCode,@NonNull String[] permissions,@NonNull int[] grantResults){
  if (grantResults.length > 0) {
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
      initializePlayer();
    }
 else {
      showToast(R.string.storage_permission_denied);
      finish();
    }
  }
 else {
  }
}
Program: 110195
Project: 110195
Buggy source:
private void handleAdGroupLoadError(){
  int adGroupIndex=this.adGroupIndex == C.INDEX_UNSET ? expectedAdGroupIndex : this.adGroupIndex;
  AdPlaybackState.AdGroup adGroup=adPlaybackState.adGroups[adGroupIndex];
  if (adGroup.count == C.LENGTH_UNSET) {
    adPlaybackState=adPlaybackState.withAdCount(adGroupIndex,Math.max(1,adGroup.states.length));
  }
  for (int i=0; i < adGroup.count; i++) {
    if (adGroup.states[i] == AdPlaybackState.AD_STATE_UNAVAILABLE) {
      if (DEBUG) {
        Log.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ adGroupIndex);
      }
      adPlaybackState=adPlaybackState.withAdLoadError(adGroupIndex,i);
    }
  }
  updateAdPlaybackState();
}

Fixed version (ground truth):
private void handleAdGroupLoadError(){
  int adGroupIndex=this.adGroupIndex == C.INDEX_UNSET ? expectedAdGroupIndex : this.adGroupIndex;
  if (adGroupIndex == C.INDEX_UNSET) {
    return;
  }
  AdPlaybackState.AdGroup adGroup=adPlaybackState.adGroups[adGroupIndex];
  if (adGroup.count == C.LENGTH_UNSET) {
    adPlaybackState=adPlaybackState.withAdCount(adGroupIndex,Math.max(1,adGroup.states.length));
    adGroup=adPlaybackState.adGroups[adGroupIndex];
  }
  for (int i=0; i < adGroup.count; i++) {
    if (adGroup.states[i] == AdPlaybackState.AD_STATE_UNAVAILABLE) {
      if (DEBUG) {
        Log.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ adGroupIndex);
      }
      adPlaybackState=adPlaybackState.withAdLoadError(adGroupIndex,i);
    }
  }
  updateAdPlaybackState();
}
Program: 110196
Project: 110196
Buggy source:
@Override public VideoProgressUpdate getContentProgress(){
  if (player == null) {
    return lastContentProgress;
  }
  boolean hasContentDuration=contentDurationMs != C.TIME_UNSET;
  long contentPositionMs;
  if (pendingContentPositionMs != C.TIME_UNSET) {
    sentPendingContentPositionMs=true;
    contentPositionMs=pendingContentPositionMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (fakeContentProgressElapsedRealtimeMs != C.TIME_UNSET) {
    long elapsedSinceEndMs=SystemClock.elapsedRealtime() - fakeContentProgressElapsedRealtimeMs;
    contentPositionMs=fakeContentProgressOffsetMs + elapsedSinceEndMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (imaAdState == IMA_AD_STATE_NONE && hasContentDuration) {
    contentPositionMs=player.getCurrentPosition();
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexAfterPositionUs(C.msToUs(contentPositionMs));
  }
 else {
    return VideoProgressUpdate.VIDEO_TIME_NOT_READY;
  }
  long contentDurationMs=hasContentDuration ? this.contentDurationMs : IMA_DURATION_UNSET;
  return new VideoProgressUpdate(contentPositionMs,contentDurationMs);
}

Fixed version (ground truth):
@Override public VideoProgressUpdate getContentProgress(){
  if (player == null) {
    return lastContentProgress;
  }
  boolean hasContentDuration=contentDurationMs != C.TIME_UNSET;
  long contentPositionMs;
  if (pendingContentPositionMs != C.TIME_UNSET) {
    sentPendingContentPositionMs=true;
    contentPositionMs=pendingContentPositionMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (fakeContentProgressElapsedRealtimeMs != C.TIME_UNSET) {
    long elapsedSinceEndMs=SystemClock.elapsedRealtime() - fakeContentProgressElapsedRealtimeMs;
    contentPositionMs=fakeContentProgressOffsetMs + elapsedSinceEndMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (imaAdState == IMA_AD_STATE_NONE && hasContentDuration) {
    contentPositionMs=player.getCurrentPosition();
    int nextAdGroupIndex=adPlaybackState.getAdGroupIndexAfterPositionUs(C.msToUs(contentPositionMs));
    if (nextAdGroupIndex != expectedAdGroupIndex && nextAdGroupIndex != C.INDEX_UNSET && C.usToMs(adPlaybackState.adGroupTimesUs[nextAdGroupIndex]) - contentPositionMs < MAXIMUM_PRELOAD_DURATION_MS) {
      expectedAdGroupIndex=nextAdGroupIndex;
    }
  }
 else {
    return VideoProgressUpdate.VIDEO_TIME_NOT_READY;
  }
  long contentDurationMs=hasContentDuration ? this.contentDurationMs : IMA_DURATION_UNSET;
  return new VideoProgressUpdate(contentPositionMs,contentDurationMs);
}
Program: 110198
Project: 110198
Buggy source:
private void handleAdGroupLoadError(){
  int adGroupIndex=this.adGroupIndex == C.INDEX_UNSET ? expectedAdGroupIndex : this.adGroupIndex;
  AdPlaybackState.AdGroup adGroup=adPlaybackState.adGroups[adGroupIndex];
  if (adGroup.count == C.LENGTH_UNSET) {
    adPlaybackState=adPlaybackState.withAdCount(adGroupIndex,Math.max(1,adGroup.states.length));
  }
  for (int i=0; i < adGroup.count; i++) {
    if (adGroup.states[i] == AdPlaybackState.AD_STATE_UNAVAILABLE) {
      if (DEBUG) {
        Log.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ adGroupIndex);
      }
      adPlaybackState=adPlaybackState.withAdLoadError(adGroupIndex,i);
    }
  }
  updateAdPlaybackState();
}

Fixed version (ground truth):
private void handleAdGroupLoadError(){
  int adGroupIndex=this.adGroupIndex == C.INDEX_UNSET ? expectedAdGroupIndex : this.adGroupIndex;
  if (adGroupIndex == C.INDEX_UNSET) {
    return;
  }
  AdPlaybackState.AdGroup adGroup=adPlaybackState.adGroups[adGroupIndex];
  if (adGroup.count == C.LENGTH_UNSET) {
    adPlaybackState=adPlaybackState.withAdCount(adGroupIndex,Math.max(1,adGroup.states.length));
    adGroup=adPlaybackState.adGroups[adGroupIndex];
  }
  for (int i=0; i < adGroup.count; i++) {
    if (adGroup.states[i] == AdPlaybackState.AD_STATE_UNAVAILABLE) {
      if (DEBUG) {
        Log.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ adGroupIndex);
      }
      adPlaybackState=adPlaybackState.withAdLoadError(adGroupIndex,i);
    }
  }
  updateAdPlaybackState();
}
Program: 110199
Project: 110199
Buggy source:
@Override public VideoProgressUpdate getContentProgress(){
  if (player == null) {
    return lastContentProgress;
  }
  boolean hasContentDuration=contentDurationMs != C.TIME_UNSET;
  long contentPositionMs;
  if (pendingContentPositionMs != C.TIME_UNSET) {
    sentPendingContentPositionMs=true;
    contentPositionMs=pendingContentPositionMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (fakeContentProgressElapsedRealtimeMs != C.TIME_UNSET) {
    long elapsedSinceEndMs=SystemClock.elapsedRealtime() - fakeContentProgressElapsedRealtimeMs;
    contentPositionMs=fakeContentProgressOffsetMs + elapsedSinceEndMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (imaAdState == IMA_AD_STATE_NONE && hasContentDuration) {
    contentPositionMs=player.getCurrentPosition();
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexAfterPositionUs(C.msToUs(contentPositionMs));
  }
 else {
    return VideoProgressUpdate.VIDEO_TIME_NOT_READY;
  }
  long contentDurationMs=hasContentDuration ? this.contentDurationMs : IMA_DURATION_UNSET;
  return new VideoProgressUpdate(contentPositionMs,contentDurationMs);
}

Fixed version (ground truth):
@Override public VideoProgressUpdate getContentProgress(){
  if (player == null) {
    return lastContentProgress;
  }
  boolean hasContentDuration=contentDurationMs != C.TIME_UNSET;
  long contentPositionMs;
  if (pendingContentPositionMs != C.TIME_UNSET) {
    sentPendingContentPositionMs=true;
    contentPositionMs=pendingContentPositionMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (fakeContentProgressElapsedRealtimeMs != C.TIME_UNSET) {
    long elapsedSinceEndMs=SystemClock.elapsedRealtime() - fakeContentProgressElapsedRealtimeMs;
    contentPositionMs=fakeContentProgressOffsetMs + elapsedSinceEndMs;
    expectedAdGroupIndex=adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
  }
 else   if (imaAdState == IMA_AD_STATE_NONE && hasContentDuration) {
    contentPositionMs=player.getCurrentPosition();
    int nextAdGroupIndex=adPlaybackState.getAdGroupIndexAfterPositionUs(C.msToUs(contentPositionMs));
    if (nextAdGroupIndex != expectedAdGroupIndex && nextAdGroupIndex != C.INDEX_UNSET && C.usToMs(adPlaybackState.adGroupTimesUs[nextAdGroupIndex]) - contentPositionMs < MAXIMUM_PRELOAD_DURATION_MS) {
      expectedAdGroupIndex=nextAdGroupIndex;
    }
  }
 else {
    return VideoProgressUpdate.VIDEO_TIME_NOT_READY;
  }
  long contentDurationMs=hasContentDuration ? this.contentDurationMs : IMA_DURATION_UNSET;
  return new VideoProgressUpdate(contentPositionMs,contentDurationMs);
}
Program: 110201
Project: 110201
Buggy source:
public ConcatenatedTimeline(Collection<MediaSourceHolder> mediaSourceHolders,int windowCount,int periodCount,ShuffleOrder shuffleOrder){
  super(shuffleOrder);
  this.windowCount=windowCount;
  this.periodCount=periodCount;
  int childCount=mediaSourceHolders.size();
  firstPeriodInChildIndices=new int[childCount];
  firstWindowInChildIndices=new int[childCount];
  timelines=new Timeline[childCount];
  uids=new int[childCount];
  childIndexByUid=new SparseIntArray();
  int index=0;
  for (  MediaSourceHolder mediaSourceHolder : mediaSourceHolders) {
    timelines[index]=mediaSourceHolder.timeline;
    firstPeriodInChildIndices[index]=mediaSourceHolder.firstPeriodIndexInChild;
    firstWindowInChildIndices[index]=mediaSourceHolder.firstWindowIndexInChild;
    uids[index]=(int)mediaSourceHolder.uid;
    childIndexByUid.put(uids[index],index++);
  }
}

Fixed version (ground truth):
public ConcatenatedTimeline(Collection<MediaSourceHolder> mediaSourceHolders,int windowCount,int periodCount,ShuffleOrder shuffleOrder){
  super(shuffleOrder);
  this.windowCount=windowCount;
  this.periodCount=periodCount;
  int childCount=mediaSourceHolders.size();
  firstPeriodInChildIndices=new int[childCount];
  firstWindowInChildIndices=new int[childCount];
  timelines=new Timeline[childCount];
  uids=new int[childCount];
  childIndexByUid=new SparseIntArray();
  int index=0;
  for (  MediaSourceHolder mediaSourceHolder : mediaSourceHolders) {
    timelines[index]=mediaSourceHolder.timeline;
    firstPeriodInChildIndices[index]=mediaSourceHolder.firstPeriodIndexInChild;
    firstWindowInChildIndices[index]=mediaSourceHolder.firstWindowIndexInChild;
    uids[index]=mediaSourceHolder.uid;
    childIndexByUid.put(uids[index],index++);
  }
}
Program: 110202
Project: 110202
Buggy source:
public MediaSourceHolder(MediaSource mediaSource,DeferredTimeline timeline,int window,int period,Object uid){
  this.mediaSource=mediaSource;
  this.timeline=timeline;
  this.firstWindowIndexInChild=window;
  this.firstPeriodIndexInChild=period;
  this.uid=uid;
}

Fixed version (ground truth):
public MediaSourceHolder(MediaSource mediaSource,DeferredTimeline timeline,int childIndex,int window,int period){
  this.mediaSource=mediaSource;
  this.timeline=timeline;
  this.childIndex=childIndex;
  this.firstWindowIndexInChild=window;
  this.firstPeriodIndexInChild=period;
  this.uid=System.identityHashCode(this);
}
Program: 110203
Project: 110203
Buggy source:
private void correctOffsets(int startIndex,int windowOffsetUpdate,int periodOffsetUpdate){
  windowCount+=windowOffsetUpdate;
  periodCount+=periodOffsetUpdate;
  for (int i=startIndex; i < mediaSourceHolders.size(); i++) {
    mediaSourceHolders.get(i).firstWindowIndexInChild+=windowOffsetUpdate;
    mediaSourceHolders.get(i).firstPeriodIndexInChild+=periodOffsetUpdate;
  }
}

Fixed version (ground truth):
private void correctOffsets(int startIndex,int childIndexUpdate,int windowOffsetUpdate,int periodOffsetUpdate){
  windowCount+=windowOffsetUpdate;
  periodCount+=periodOffsetUpdate;
  for (int i=startIndex; i < mediaSourceHolders.size(); i++) {
    mediaSourceHolders.get(i).childIndex+=childIndexUpdate;
    mediaSourceHolders.get(i).firstWindowIndexInChild+=windowOffsetUpdate;
    mediaSourceHolders.get(i).firstPeriodIndexInChild+=periodOffsetUpdate;
  }
}
Program: 110204
Project: 110204
Buggy source:
private void addMediaSourceInternal(int newIndex,MediaSource newMediaSource){
  final MediaSourceHolder newMediaSourceHolder;
  Object newUid=System.identityHashCode(newMediaSource);
  DeferredTimeline newTimeline=new DeferredTimeline();
  if (newIndex > 0) {
    MediaSourceHolder previousHolder=mediaSourceHolders.get(newIndex - 1);
    newMediaSourceHolder=new MediaSourceHolder(newMediaSource,newTimeline,previousHolder.firstWindowIndexInChild + previousHolder.timeline.getWindowCount(),previousHolder.firstPeriodIndexInChild + previousHolder.timeline.getPeriodCount(),newUid);
  }
 else {
    newMediaSourceHolder=new MediaSourceHolder(newMediaSource,newTimeline,0,0,newUid);
  }
  correctOffsets(newIndex,newTimeline.getWindowCount(),newTimeline.getPeriodCount());
  mediaSourceHolders.add(newIndex,newMediaSourceHolder);
  prepareChildSource(newMediaSourceHolder,newMediaSourceHolder.mediaSource);
}

Fixed version (ground truth):
private void addMediaSourceInternal(int newIndex,MediaSource newMediaSource){
  final MediaSourceHolder newMediaSourceHolder;
  DeferredTimeline newTimeline=new DeferredTimeline();
  if (newIndex > 0) {
    MediaSourceHolder previousHolder=mediaSourceHolders.get(newIndex - 1);
    newMediaSourceHolder=new MediaSourceHolder(newMediaSource,newTimeline,newIndex,previousHolder.firstWindowIndexInChild + previousHolder.timeline.getWindowCount(),previousHolder.firstPeriodIndexInChild + previousHolder.timeline.getPeriodCount());
  }
 else {
    newMediaSourceHolder=new MediaSourceHolder(newMediaSource,newTimeline,0,0,0);
  }
  correctOffsets(newIndex,1,newTimeline.getWindowCount(),newTimeline.getPeriodCount());
  mediaSourceHolders.add(newIndex,newMediaSourceHolder);
  prepareChildSource(newMediaSourceHolder,newMediaSourceHolder.mediaSource);
}
Program: 110205
Project: 110205
Buggy source:
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder,Timeline timeline){
  if (mediaSourceHolder == null) {
    throw new IllegalArgumentException();
  }
  DeferredTimeline deferredTimeline=mediaSourceHolder.timeline;
  if (deferredTimeline.getTimeline() == timeline) {
    return;
  }
  int windowOffsetUpdate=timeline.getWindowCount() - deferredTimeline.getWindowCount();
  int periodOffsetUpdate=timeline.getPeriodCount() - deferredTimeline.getPeriodCount();
  if (windowOffsetUpdate != 0 || periodOffsetUpdate != 0) {
    int index=findMediaSourceHolderByPeriodIndex(mediaSourceHolder.firstPeriodIndexInChild);
    correctOffsets(index + 1,windowOffsetUpdate,periodOffsetUpdate);
  }
  mediaSourceHolder.timeline=deferredTimeline.cloneWithNewTimeline(timeline);
  if (!mediaSourceHolder.isPrepared) {
    for (int i=deferredMediaPeriods.size() - 1; i >= 0; i--) {
      if (deferredMediaPeriods.get(i).mediaSource == mediaSourceHolder.mediaSource) {
        deferredMediaPeriods.get(i).createPeriod();
        deferredMediaPeriods.remove(i);
      }
    }
  }
  mediaSourceHolder.isPrepared=true;
  maybeNotifyListener(null);
}

Fixed version (ground truth):
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder,Timeline timeline){
  if (mediaSourceHolder == null) {
    throw new IllegalArgumentException();
  }
  DeferredTimeline deferredTimeline=mediaSourceHolder.timeline;
  if (deferredTimeline.getTimeline() == timeline) {
    return;
  }
  int windowOffsetUpdate=timeline.getWindowCount() - deferredTimeline.getWindowCount();
  int periodOffsetUpdate=timeline.getPeriodCount() - deferredTimeline.getPeriodCount();
  if (windowOffsetUpdate != 0 || periodOffsetUpdate != 0) {
    correctOffsets(mediaSourceHolder.childIndex + 1,0,windowOffsetUpdate,periodOffsetUpdate);
  }
  mediaSourceHolder.timeline=deferredTimeline.cloneWithNewTimeline(timeline);
  if (!mediaSourceHolder.isPrepared) {
    for (int i=deferredMediaPeriods.size() - 1; i >= 0; i--) {
      if (deferredMediaPeriods.get(i).mediaSource == mediaSourceHolder.mediaSource) {
        deferredMediaPeriods.get(i).createPeriod();
        deferredMediaPeriods.remove(i);
      }
    }
  }
  mediaSourceHolder.isPrepared=true;
  maybeNotifyListener(null);
}
Program: 110206
Project: 110206
Buggy source:
private void removeMediaSourceInternal(int index){
  MediaSourceHolder holder=mediaSourceHolders.get(index);
  mediaSourceHolders.remove(index);
  Timeline oldTimeline=holder.timeline;
  correctOffsets(index,-oldTimeline.getWindowCount(),-oldTimeline.getPeriodCount());
  releaseChildSource(holder);
}

Fixed version (ground truth):
private void removeMediaSourceInternal(int index){
  MediaSourceHolder holder=mediaSourceHolders.get(index);
  mediaSourceHolders.remove(index);
  Timeline oldTimeline=holder.timeline;
  correctOffsets(index,-1,-oldTimeline.getWindowCount(),-oldTimeline.getPeriodCount());
  releaseChildSource(holder);
}
Program: 110207
Project: 110207
Buggy source:
private void closeCurrentSource() throws IOException {
  if (currentDataSource == null) {
    return;
  }
  try {
    currentDataSource.close();
    currentDataSource=null;
    currentDataSpecLengthUnset=false;
  }
  finally {
    if (currentHoleSpan != null) {
      cache.releaseHoleSpan(currentHoleSpan);
      currentHoleSpan=null;
    }
  }
}

Fixed version (ground truth):
private void closeCurrentSource() throws IOException {
  if (currentDataSource == null) {
    return;
  }
  try {
    currentDataSource.close();
  }
  finally {
    currentDataSource=null;
    currentDataSpecLengthUnset=false;
    if (currentHoleSpan != null) {
      cache.releaseHoleSpan(currentHoleSpan);
      currentHoleSpan=null;
    }
  }
}
Program: 110209
Project: 110209
Buggy source:
@Override public void onLoadCanceled(ParsingLoadable<SsManifest> loadable,long elapsedRealtimeMs,long loadDurationMs,boolean released){
  eventDispatcher.loadCompleted(loadable.dataSpec,loadable.type,elapsedRealtimeMs,loadDurationMs,loadable.bytesLoaded());
}

Fixed version (ground truth):
@Override public void onLoadCanceled(ParsingLoadable<SsManifest> loadable,long elapsedRealtimeMs,long loadDurationMs,boolean released){
  eventDispatcher.loadCanceled(loadable.dataSpec,loadable.type,elapsedRealtimeMs,loadDurationMs,loadable.bytesLoaded());
}
Program: 110210
Project: 110210
Buggy source:
private void processEndOfStream() throws ExoPlaybackException {
  outputStreamEnded=true;
  try {
    audioSink.playToEndOfStream();
  }
 catch (  AudioSink.WriteException e) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(),getIndex());
  }
}

Fixed version (ground truth):
private void processEndOfStream() throws ExoPlaybackException {
  outputStreamEnded=true;
  try {
    audioSink.playToEndOfStream();
  }
 catch (  AudioSink.WriteException e) {
    throw ExoPlaybackException.createForRenderer(e,getIndex());
  }
}
Program: 110211
Project: 110211
Buggy source:
public void testAddGetRemove() throws Exception {
  final String key1="String_Node_Str";
  final String key2="String_Node_Str";
  final String key3="String_Node_Str";
  CachedContent cachedContent1=new CachedContent(5,key1,10);
  index.addNew(cachedContent1);
  CachedContent cachedContent2=index.add(key2);
  assertTrue(cachedContent1.id != cachedContent2.id);
  File cacheSpanFile=SimpleCacheSpanTest.createCacheSpanFile(cacheDir,cachedContent1.id,10,20,30);
  SimpleCacheSpan span=SimpleCacheSpan.createCacheEntry(cacheSpanFile,index);
  assertNotNull(span);
  cachedContent1.addSpan(span);
  assertEquals(cachedContent1,index.get(key1));
  assertEquals(cachedContent2,index.get(key2));
  assertNull(index.get(key3));
  Collection<CachedContent> cachedContents=index.getAll();
  assertEquals(2,cachedContents.size());
  assertTrue(Arrays.asList(cachedContent1,cachedContent2).containsAll(cachedContents));
  Set<String> keys=index.getKeys();
  assertEquals(2,keys.size());
  assertTrue(Arrays.asList(key1,key2).containsAll(keys));
  assertEquals(key1,index.getKeyForId(cachedContent1.id));
  assertEquals(key2,index.getKeyForId(cachedContent2.id));
  index.removeEmpty(key2);
  index.removeEmpty(key3);
  assertEquals(cachedContent1,index.get(key1));
  assertNull(index.get(key2));
  assertTrue(cacheSpanFile.exists());
  index.addNew(cachedContent2);
  index.removeEmpty();
  assertEquals(cachedContent1,index.get(key1));
  assertNull(index.get(key2));
  assertTrue(cacheSpanFile.exists());
}

Fixed version (ground truth):
public void testAddGetRemove() throws Exception {
  final String key1="String_Node_Str";
  final String key2="String_Node_Str";
  final String key3="String_Node_Str";
  CachedContent cachedContent1=new CachedContent(5,key1,10);
  index.addNew(cachedContent1);
  CachedContent cachedContent2=index.getOrAdd(key2);
  assertTrue(cachedContent1.id != cachedContent2.id);
  File cacheSpanFile=SimpleCacheSpanTest.createCacheSpanFile(cacheDir,cachedContent1.id,10,20,30);
  SimpleCacheSpan span=SimpleCacheSpan.createCacheEntry(cacheSpanFile,index);
  assertNotNull(span);
  cachedContent1.addSpan(span);
  assertEquals(cachedContent1,index.get(key1));
  assertEquals(cachedContent2,index.get(key2));
  assertNull(index.get(key3));
  Collection<CachedContent> cachedContents=index.getAll();
  assertEquals(2,cachedContents.size());
  assertTrue(Arrays.asList(cachedContent1,cachedContent2).containsAll(cachedContents));
  Set<String> keys=index.getKeys();
  assertEquals(2,keys.size());
  assertTrue(Arrays.asList(key1,key2).containsAll(keys));
  assertEquals(key1,index.getKeyForId(cachedContent1.id));
  assertEquals(key2,index.getKeyForId(cachedContent2.id));
  index.maybeRemove(key2);
  index.maybeRemove(key3);
  assertEquals(cachedContent1,index.get(key1));
  assertNull(index.get(key2));
  assertTrue(cacheSpanFile.exists());
  index.addNew(cachedContent2);
  index.removeEmpty();
  assertEquals(cachedContent1,index.get(key1));
  assertNull(index.get(key2));
  assertTrue(cacheSpanFile.exists());
}
Program: 110212
Project: 110212
Buggy source:
private void assertStoredAndLoadedEqual(CachedContentIndex index,CachedContentIndex index2) throws IOException {
  index.addNew(new CachedContent(5,"String_Node_Str",10));
  index.add("String_Node_Str");
  index.store();
  index2.load();
  Set<String> keys=index.getKeys();
  Set<String> keys2=index2.getKeys();
  assertEquals(keys,keys2);
  for (  String key : keys) {
    assertEquals(index.getContentLength(key),index2.getContentLength(key));
    assertEquals(index.get(key).getSpans(),index2.get(key).getSpans());
  }
}

Fixed version (ground truth):
private void assertStoredAndLoadedEqual(CachedContentIndex index,CachedContentIndex index2) throws IOException {
  index.addNew(new CachedContent(5,"String_Node_Str",10));
  index.getOrAdd("String_Node_Str");
  index.store();
  index2.load();
  Set<String> keys=index.getKeys();
  Set<String> keys2=index2.getKeys();
  assertEquals(keys,keys2);
  for (  String key : keys) {
    assertEquals(index.getContentLength(key),index2.getContentLength(key));
    assertEquals(index.get(key).getSpans(),index2.get(key).getSpans());
  }
}
Program: 110213
Project: 110213
Buggy source:
@Override public int read(byte[] buffer,int offset,int readLength) throws IOException {
  if (readLength == 0) {
    return 0;
  }
  if (bytesRemaining == 0) {
    return C.RESULT_END_OF_INPUT;
  }
  try {
    if (readPosition >= checkCachePosition) {
      openNextSource();
    }
    int bytesRead=currentDataSource.read(buffer,offset,readLength);
    if (bytesRead != C.RESULT_END_OF_INPUT) {
      if (currentDataSource == cacheReadDataSource) {
        totalCachedBytesRead+=bytesRead;
      }
      readPosition+=bytesRead;
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining-=bytesRead;
      }
    }
 else     if (currentDataSpecLengthUnset) {
      setBytesRemaining(0);
    }
 else     if (bytesRemaining > 0 || bytesRemaining == C.LENGTH_UNSET) {
      openNextSource();
      return read(buffer,offset,readLength);
    }
    return bytesRead;
  }
 catch (  IOException e) {
    if (currentDataSpecLengthUnset && isCausedByPositionOutOfRange(e)) {
      setBytesRemaining(0);
      return C.RESULT_END_OF_INPUT;
    }
    handleBeforeThrow(e);
    throw e;
  }
}

Fixed version (ground truth):
@Override public int read(byte[] buffer,int offset,int readLength) throws IOException {
  if (readLength == 0) {
    return 0;
  }
  if (bytesRemaining == 0) {
    return C.RESULT_END_OF_INPUT;
  }
  try {
    if (readPosition >= checkCachePosition) {
      openNextSource(true);
    }
    int bytesRead=currentDataSource.read(buffer,offset,readLength);
    if (bytesRead != C.RESULT_END_OF_INPUT) {
      if (currentDataSource == cacheReadDataSource) {
        totalCachedBytesRead+=bytesRead;
      }
      readPosition+=bytesRead;
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining-=bytesRead;
      }
    }
 else {
      closeCurrentSource();
      if (currentDataSpecLengthUnset) {
        setBytesRemaining(0);
      }
 else       if (bytesRemaining > 0 || bytesRemaining == C.LENGTH_UNSET) {
        openNextSource(false);
        return read(buffer,offset,readLength);
      }
    }
    return bytesRead;
  }
 catch (  IOException e) {
    if (currentDataSpecLengthUnset && isCausedByPositionOutOfRange(e)) {
      setBytesRemaining(0);
      return C.RESULT_END_OF_INPUT;
    }
    handleBeforeThrow(e);
    throw e;
  }
}
Program: 110215
Project: 110215
Buggy source:
@Override public long open(DataSpec dataSpec) throws IOException {
  try {
    uri=dataSpec.uri;
    flags=dataSpec.flags;
    key=CacheUtil.getKey(dataSpec);
    readPosition=dataSpec.position;
    currentRequestIgnoresCache=(ignoreCacheOnError && seenCacheError) || (dataSpec.length == C.LENGTH_UNSET && ignoreCacheForUnsetLengthRequests);
    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining=dataSpec.length;
    }
 else {
      bytesRemaining=cache.getContentLength(key);
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining-=dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource();
    return bytesRemaining;
  }
 catch (  IOException e) {
    handleBeforeThrow(e);
    throw e;
  }
}

Fixed version (ground truth):
@Override public long open(DataSpec dataSpec) throws IOException {
  try {
    uri=dataSpec.uri;
    flags=dataSpec.flags;
    key=CacheUtil.getKey(dataSpec);
    readPosition=dataSpec.position;
    currentRequestIgnoresCache=(ignoreCacheOnError && seenCacheError) || (dataSpec.length == C.LENGTH_UNSET && ignoreCacheForUnsetLengthRequests);
    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining=dataSpec.length;
    }
 else {
      bytesRemaining=cache.getContentLength(key);
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining-=dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource(false);
    return bytesRemaining;
  }
 catch (  IOException e) {
    handleBeforeThrow(e);
    throw e;
  }
}
Program: 110216
Project: 110216
Buggy source:
/** 
 * Removes empty   {@link CachedContent} instances from index. 
 */
public void removeEmpty(){
  ArrayList<String> cachedContentToBeRemoved=new ArrayList<>();
  for (  CachedContent cachedContent : keyToContent.values()) {
    if (cachedContent.isEmpty()) {
      cachedContentToBeRemoved.add(cachedContent.key);
    }
  }
  for (int i=0; i < cachedContentToBeRemoved.size(); i++) {
    removeEmpty(cachedContentToBeRemoved.get(i));
  }
}

Fixed version (ground truth):
/** 
 * Removes empty and not locked   {@link CachedContent} instances from index. 
 */
public void removeEmpty(){
  String[] keys=new String[keyToContent.size()];
  keyToContent.keySet().toArray(keys);
  for (  String key : keys) {
    maybeRemove(key);
  }
}
Program: 110217
Project: 110217
Buggy source:
/** 
 * Returns an existing or new id assigned to the given key. 
 */
public int assignIdForKey(String key){
  return add(key).id;
}

Fixed version (ground truth):
/** 
 * Returns an existing or new id assigned to the given key. 
 */
public int assignIdForKey(String key){
  return getOrAdd(key).id;
}
Program: 110218
Project: 110218
Buggy source:
/** 
 * Adds a cached span to the in-memory representation.
 * @param span The span to be added.
 */
private void addSpan(SimpleCacheSpan span){
  index.add(span.key).addSpan(span);
  totalSpace+=span.length;
  notifySpanAdded(span);
}

Fixed version (ground truth):
/** 
 * Adds a cached span to the in-memory representation.
 * @param span The span to be added.
 */
private void addSpan(SimpleCacheSpan span){
  index.getOrAdd(span.key).addSpan(span);
  totalSpace+=span.length;
  notifySpanAdded(span);
}
Program: 110219
Project: 110219
Buggy source:
@Override public synchronized File startFile(String key,long position,long maxLength) throws CacheException {
  Assertions.checkState(lockedSpans.containsKey(key));
  if (!cacheDir.exists()) {
    removeStaleSpansAndCachedContents();
    cacheDir.mkdirs();
  }
  evictor.onStartFile(this,key,position,maxLength);
  return SimpleCacheSpan.getCacheFile(cacheDir,index.assignIdForKey(key),position,System.currentTimeMillis());
}

Fixed version (ground truth):
@Override public synchronized File startFile(String key,long position,long maxLength) throws CacheException {
  CachedContent cachedContent=index.get(key);
  Assertions.checkNotNull(cachedContent);
  Assertions.checkState(cachedContent.isLocked());
  if (!cacheDir.exists()) {
    removeStaleSpansAndCachedContents();
    cacheDir.mkdirs();
  }
  evictor.onStartFile(this,key,position,maxLength);
  return SimpleCacheSpan.getCacheFile(cacheDir,cachedContent.id,position,System.currentTimeMillis());
}
Program: 110220
Project: 110220
Buggy source:
@Override public synchronized void releaseHoleSpan(CacheSpan holeSpan){
  Assertions.checkState(holeSpan == lockedSpans.remove(holeSpan.key));
  notifyAll();
}

Fixed version (ground truth):
@Override public synchronized void releaseHoleSpan(CacheSpan holeSpan){
  CachedContent cachedContent=index.get(holeSpan.key);
  Assertions.checkNotNull(cachedContent);
  Assertions.checkState(cachedContent.isLocked());
  cachedContent.setLocked(false);
  notifyAll();
}
Program: 110221
Project: 110221
Buggy source:
/** 
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence the directory cannot be used to store other files.
 * @param cacheDir A dedicated cache directory.
 * @param evictor The evictor to be used.
 * @param index The CachedContentIndex to be used.
 */
SimpleCache(File cacheDir,CacheEvictor evictor,CachedContentIndex index){
  this.cacheDir=cacheDir;
  this.evictor=evictor;
  this.lockedSpans=new HashMap<>();
  this.index=index;
  this.listeners=new HashMap<>();
  final ConditionVariable conditionVariable=new ConditionVariable();
  new Thread("String_Node_Str"){
    @Override public void run(){
synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
        SimpleCache.this.evictor.onCacheInitialized();
      }
    }
  }
.start();
  conditionVariable.block();
}

Fixed version (ground truth):
/** 
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence the directory cannot be used to store other files.
 * @param cacheDir A dedicated cache directory.
 * @param evictor The evictor to be used.
 * @param index The CachedContentIndex to be used.
 */
SimpleCache(File cacheDir,CacheEvictor evictor,CachedContentIndex index){
  this.cacheDir=cacheDir;
  this.evictor=evictor;
  this.index=index;
  this.listeners=new HashMap<>();
  final ConditionVariable conditionVariable=new ConditionVariable();
  new Thread("String_Node_Str"){
    @Override public void run(){
synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
        SimpleCache.this.evictor.onCacheInitialized();
      }
    }
  }
.start();
  conditionVariable.block();
}
Program: 110222
Project: 110222
Buggy source:
@Override public synchronized void commitFile(File file) throws CacheException {
  SimpleCacheSpan span=SimpleCacheSpan.createCacheEntry(file,index);
  Assertions.checkState(span != null);
  Assertions.checkState(lockedSpans.containsKey(span.key));
  if (!file.exists()) {
    return;
  }
  if (file.length() == 0) {
    file.delete();
    return;
  }
  Long length=getContentLength(span.key);
  if (length != C.LENGTH_UNSET) {
    Assertions.checkState((span.position + span.length) <= length);
  }
  addSpan(span);
  index.store();
  notifyAll();
}

Fixed version (ground truth):
@Override public synchronized void commitFile(File file) throws CacheException {
  SimpleCacheSpan span=SimpleCacheSpan.createCacheEntry(file,index);
  Assertions.checkState(span != null);
  CachedContent cachedContent=index.get(span.key);
  Assertions.checkNotNull(cachedContent);
  Assertions.checkState(cachedContent.isLocked());
  if (!file.exists()) {
    return;
  }
  if (file.length() == 0) {
    file.delete();
    return;
  }
  Long length=cachedContent.getLength();
  if (length != C.LENGTH_UNSET) {
    Assertions.checkState((span.position + span.length) <= length);
  }
  addSpan(span);
  index.store();
  notifyAll();
}