Program: 4611
Project: 4611
Buggy source:
/** 
 * Assigns a white area or a grey area to a downloader. Sets the state, and checks if this downloader has been interrupted.
 * @param dloader The downloader to which this method assigns eithera grey area or white area.
 * @param refSleepTime this parameter is used for pass by reference, thismethod puts the minPollTime as the 0th element of this array.
 * @return 0 if (the server is not giving us the file)TryAgainLater, FileNotFound, NotSharing, Stopped, Misc IOE otherwise if queued return 1 otherwise if connected successfully return 2 otherwise if NoSuchElement( we have no areas to steal) return 3 otherwise if rfd was partial uploader and gave us ranges to try return 4
 */
private int assignAndRequest(HTTPDownloader dloader,int[] refSleepTime,boolean http11){
synchronized (stealLock) {
    RemoteFileDesc rfd=dloader.getRemoteFileDesc();
    boolean updateNeeded=true;
    try {
      if (!needed.isEmpty()) {
        assignWhite(dloader,http11);
      }
 else {
        updateNeeded=false;
        assignGrey(dloader,http11);
      }
      updateNeeded=false;
    }
 catch (    NoSuchElementException nsex) {
      if (RECORD_STATS)       DownloadStat.NSE_EXCEPTION.incrementStat();
      Assert.that(updateNeeded == false,"String_Node_Str");
      debug("String_Node_Str" + dloader);
synchronized (this) {
        files.add(rfd);
      }
      return 3;
    }
catch (    NoSuchRangeException nsrx) {
      if (RECORD_STATS)       DownloadStat.NSR_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
synchronized (this) {
        rfd.setAvailableRanges(null);
        busy.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    TryAgainLaterException talx) {
      if (RECORD_STATS)       DownloadStat.TAL_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
synchronized (this) {
        busy.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    RangeNotAvailableException rnae) {
      if (RECORD_STATS)       DownloadStat.RNA_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      rfd.resetFailedCount();
      informMesh(dloader.getRemoteFileDesc(),true);
      return 4;
    }
catch (    FileNotFoundException fnfx) {
      if (RECORD_STATS)       DownloadStat.FNF_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      informMesh(dloader.getRemoteFileDesc(),false);
      return 0;
    }
catch (    NotSharingException nsx) {
      if (RECORD_STATS)       DownloadStat.NS_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      informMesh(dloader.getRemoteFileDesc(),false);
      return 0;
    }
catch (    QueuedException qx) {
      if (RECORD_STATS)       DownloadStat.Q_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      refSleepTime[0]=qx.getMinPollTime() * 1000 + 1000;
synchronized (this) {
        if (dloaders.size() == 0) {
          setState(REMOTE_QUEUED);
        }
        int oldPos=queuePosition.equals("String_Node_Str") ? Integer.MAX_VALUE : Integer.parseInt(queuePosition);
        int newPos=qx.getQueuePosition();
        if (newPos < oldPos) {
          queuePosition="String_Node_Str" + newPos;
          queuedVendor=dloader.getVendor();
        }
      }
      rfd.resetFailedCount();
      return 1;
    }
catch (    ProblemReadingHeaderException prhe) {
      if (RECORD_STATS)       DownloadStat.PRH_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      informMesh(dloader.getRemoteFileDesc(),false);
      return 0;
    }
catch (    UnknownCodeException uce) {
      if (RECORD_STATS)       DownloadStat.UNKNOWN_CODE_EXCEPTION.incrementStat();
      debug("String_Node_Str" + uce.getCode() + "String_Node_Str"+ dloader);
      informMesh(dloader.getRemoteFileDesc(),false);
      return 0;
    }
catch (    IOException iox) {
      if (RECORD_STATS)       DownloadStat.IO_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      rfd.incrementFailedCount();
      if (rfd.getFailedCount() < 2) synchronized (this) {
        busy.add(rfd);
      }
 else       informMesh(dloader.getRemoteFileDesc(),false);
      return 0;
    }
 finally {
      AlternateLocationCollection c=dloader.getAltLocsReceived();
      if (c != null) {
synchronized (c) {
          Iterator iter=c.iterator();
          while (iter.hasNext()) {
            AlternateLocation al=(AlternateLocation)iter.next();
            RemoteFileDesc rfd1=al.createRemoteFileDesc(dloader.getRemoteFileDesc().getSize());
            addDownload(rfd1,false);
          }
        }
      }
      if (updateNeeded)       updateNeeded(dloader);
    }
    if (RECORD_STATS && rfd.getFailedCount() > 0)     DownloadStat.RETRIED_SUCCESS.incrementStat();
    rfd.resetFailedCount();
synchronized (this) {
      setState(DOWNLOADING);
    }
    if (stopped) {
      debug("String_Node_Str");
      updateNeeded(dloader);
synchronized (this) {
        files.add(rfd);
      }
      return 0;
    }
synchronized (this) {
      dloaders.add(dloader);
      chatList.addHost(dloader);
      browseList.addHost(dloader);
    }
    if (RECORD_STATS)     DownloadStat.RESPONSE_OK.incrementStat();
    return 2;
  }
}

Fixed version (ground truth):
/** 
 * Assigns a white area or a grey area to a downloader. Sets the state, and checks if this downloader has been interrupted.
 * @param dloader The downloader to which this method assigns eithera grey area or white area.
 * @param refSleepTime this parameter is used for pass by reference, thismethod puts the minPollTime as the 0th element of this array.
 * @return 0 if (the server is not giving us the file)TryAgainLater, FileNotFound, NotSharing, Stopped, Misc IOE otherwise if queued return 1 otherwise if connected successfully return 2 otherwise if NoSuchElement( we have no areas to steal) return 3 otherwise if rfd was partial uploader and gave us ranges to try return 4
 */
private int assignAndRequest(HTTPDownloader dloader,int[] refSleepTime,boolean http11){
synchronized (stealLock) {
    RemoteFileDesc rfd=dloader.getRemoteFileDesc();
    boolean updateNeeded=true;
    try {
      if (!needed.isEmpty()) {
        assignWhite(dloader,http11);
      }
 else {
        updateNeeded=false;
        assignGrey(dloader,http11);
      }
      updateNeeded=false;
    }
 catch (    NoSuchElementException nsex) {
      if (RECORD_STATS)       DownloadStat.NSE_EXCEPTION.incrementStat();
      Assert.that(updateNeeded == false,"String_Node_Str");
      debug("String_Node_Str" + dloader);
synchronized (this) {
        files.add(rfd);
      }
      return 3;
    }
catch (    NoSuchRangeException nsrx) {
      if (RECORD_STATS)       DownloadStat.NSR_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
synchronized (this) {
        rfd.setAvailableRanges(null);
        busy.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    TryAgainLaterException talx) {
      if (RECORD_STATS)       DownloadStat.TAL_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
synchronized (this) {
        busy.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    RangeNotAvailableException rnae) {
      if (RECORD_STATS)       DownloadStat.RNA_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      rfd.resetFailedCount();
      informMesh(rfd,true);
      return 4;
    }
catch (    FileNotFoundException fnfx) {
      if (RECORD_STATS)       DownloadStat.FNF_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      informMesh(rfd,false);
      return 0;
    }
catch (    NotSharingException nsx) {
      if (RECORD_STATS)       DownloadStat.NS_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      informMesh(rfd,false);
      return 0;
    }
catch (    QueuedException qx) {
      if (RECORD_STATS)       DownloadStat.Q_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      refSleepTime[0]=qx.getMinPollTime() * 1000 + 1000;
synchronized (this) {
        if (dloaders.size() == 0) {
          setState(REMOTE_QUEUED);
        }
        int oldPos=queuePosition.equals("String_Node_Str") ? Integer.MAX_VALUE : Integer.parseInt(queuePosition);
        int newPos=qx.getQueuePosition();
        if (newPos < oldPos) {
          queuePosition="String_Node_Str" + newPos;
          queuedVendor=dloader.getVendor();
        }
      }
      rfd.resetFailedCount();
      return 1;
    }
catch (    ProblemReadingHeaderException prhe) {
      if (RECORD_STATS)       DownloadStat.PRH_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      informMesh(rfd,false);
      return 0;
    }
catch (    UnknownCodeException uce) {
      if (RECORD_STATS)       DownloadStat.UNKNOWN_CODE_EXCEPTION.incrementStat();
      debug("String_Node_Str" + uce.getCode() + "String_Node_Str"+ dloader);
      informMesh(rfd,false);
      return 0;
    }
catch (    IOException iox) {
      if (RECORD_STATS)       DownloadStat.IO_EXCEPTION.incrementStat();
      debug("String_Node_Str" + dloader);
      rfd.incrementFailedCount();
      if (rfd.getFailedCount() < 2) synchronized (this) {
        busy.add(rfd);
      }
 else       informMesh(rfd,false);
      return 0;
    }
 finally {
      AlternateLocationCollection c=dloader.getAltLocsReceived();
      if (c != null) {
synchronized (c) {
          Iterator iter=c.iterator();
          while (iter.hasNext()) {
            AlternateLocation al=(AlternateLocation)iter.next();
            RemoteFileDesc rfd1=al.createRemoteFileDesc(rfd.getSize());
            addDownload(rfd1,false);
          }
        }
      }
      if (updateNeeded)       updateNeeded(dloader);
    }
    if (RECORD_STATS && rfd.getFailedCount() > 0)     DownloadStat.RETRIED_SUCCESS.incrementStat();
    rfd.resetFailedCount();
synchronized (this) {
      setState(DOWNLOADING);
    }
    if (stopped) {
      debug("String_Node_Str");
      updateNeeded(dloader);
synchronized (this) {
        files.add(rfd);
      }
      return 0;
    }
synchronized (this) {
      dloaders.add(dloader);
      chatList.addHost(dloader);
      browseList.addHost(dloader);
    }
    if (RECORD_STATS)     DownloadStat.RESPONSE_OK.incrementStat();
    return 2;
  }
}