Program: 4502
Project: 4502
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 refQueueInfo this parameter is used for pass by reference, thismethod puts the minPollTime as the 0th element of this array, and the remote queue postion of the downloader in the 1st element
 * @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[] refQueueInfo,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");
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,nsex);
synchronized (this) {
        files.add(rfd);
      }
      return 3;
    }
catch (    NoSuchRangeException nsrx) {
      if (RECORD_STATS)       DownloadStat.NSR_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,nsrx);
synchronized (this) {
        rfd.setAvailableRanges(null);
        if (!rfd.isBusy())         rfd.setRetryAfter(NO_RANGES_RETRY_AFTER);
        files.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    TryAgainLaterException talx) {
      if (RECORD_STATS)       DownloadStat.TAL_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,talx);
      if (!rfd.isBusy()) {
        rfd.setRetryAfter(RETRY_AFTER_NONE_ACTIVE);
      }
synchronized (this) {
        if (dloaders.size() > 0 && rfd.getWaitTime() < RETRY_AFTER_SOME_ACTIVE)         rfd.setRetryAfter(RETRY_AFTER_SOME_ACTIVE);
        files.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    RangeNotAvailableException rnae) {
      if (RECORD_STATS)       DownloadStat.RNA_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,rnae);
      rfd.resetFailedCount();
      informMesh(rfd,true);
      return 4;
    }
catch (    FileNotFoundException fnfx) {
      if (RECORD_STATS)       DownloadStat.FNF_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,fnfx);
      informMesh(rfd,false);
      return 0;
    }
catch (    NotSharingException nsx) {
      if (RECORD_STATS)       DownloadStat.NS_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,nsx);
      informMesh(rfd,false);
      return 0;
    }
catch (    QueuedException qx) {
      if (RECORD_STATS)       DownloadStat.Q_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,qx);
      refQueueInfo[0]=qx.getMinPollTime() * 1000 + 1000;
      refQueueInfo[1]=qx.getQueuePosition();
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();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,prhe);
      informMesh(rfd,false);
      return 0;
    }
catch (    UnknownCodeException uce) {
      if (RECORD_STATS)       DownloadStat.UNKNOWN_CODE_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + uce.getCode() + "String_Node_Str"+ dloader,uce);
      informMesh(rfd,false);
      return 0;
    }
catch (    IOException iox) {
      if (RECORD_STATS)       DownloadStat.IO_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,iox);
      rfd.incrementFailedCount();
      if (rfd.getFailedCount() < 2) {
        rfd.setRetryAfter(FAILED_RETRY_AFTER);
synchronized (this) {
          files.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) {
      LOG.trace("String_Node_Str");
      updateNeeded(dloader);
synchronized (this) {
        files.add(rfd);
      }
      return 0;
    }
synchronized (this) {
      if (!dloaders.contains(dloader))       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 refQueueInfo this parameter is used for pass by reference, thismethod puts the minPollTime as the 0th element of this array, and the remote queue postion of the downloader in the 1st element
 * @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[] refQueueInfo,boolean http11){
synchronized (stealLock) {
    RemoteFileDesc rfd=dloader.getRemoteFileDesc();
    boolean updateNeeded=true;
    boolean shouldAssignWhite=false;
synchronized (this) {
      shouldAssignWhite=!needed.isEmpty();
    }
    try {
      if (shouldAssignWhite) {
        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");
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,nsex);
synchronized (this) {
        files.add(rfd);
      }
      return 3;
    }
catch (    NoSuchRangeException nsrx) {
      if (RECORD_STATS)       DownloadStat.NSR_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,nsrx);
synchronized (this) {
        rfd.setAvailableRanges(null);
        if (!rfd.isBusy())         rfd.setRetryAfter(NO_RANGES_RETRY_AFTER);
        files.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    TryAgainLaterException talx) {
      if (RECORD_STATS)       DownloadStat.TAL_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,talx);
      if (!rfd.isBusy()) {
        rfd.setRetryAfter(RETRY_AFTER_NONE_ACTIVE);
      }
synchronized (this) {
        if (dloaders.size() > 0 && rfd.getWaitTime() < RETRY_AFTER_SOME_ACTIVE)         rfd.setRetryAfter(RETRY_AFTER_SOME_ACTIVE);
        files.add(rfd);
      }
      rfd.resetFailedCount();
      return 0;
    }
catch (    RangeNotAvailableException rnae) {
      if (RECORD_STATS)       DownloadStat.RNA_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,rnae);
      rfd.resetFailedCount();
      informMesh(rfd,true);
      return 4;
    }
catch (    FileNotFoundException fnfx) {
      if (RECORD_STATS)       DownloadStat.FNF_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,fnfx);
      informMesh(rfd,false);
      return 0;
    }
catch (    NotSharingException nsx) {
      if (RECORD_STATS)       DownloadStat.NS_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,nsx);
      informMesh(rfd,false);
      return 0;
    }
catch (    QueuedException qx) {
      if (RECORD_STATS)       DownloadStat.Q_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,qx);
      refQueueInfo[0]=qx.getMinPollTime() * 1000 + 1000;
      refQueueInfo[1]=qx.getQueuePosition();
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();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,prhe);
      informMesh(rfd,false);
      return 0;
    }
catch (    UnknownCodeException uce) {
      if (RECORD_STATS)       DownloadStat.UNKNOWN_CODE_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + uce.getCode() + "String_Node_Str"+ dloader,uce);
      informMesh(rfd,false);
      return 0;
    }
catch (    IOException iox) {
      if (RECORD_STATS)       DownloadStat.IO_EXCEPTION.incrementStat();
      if (LOG.isDebugEnabled())       LOG.debug("String_Node_Str" + dloader,iox);
      rfd.incrementFailedCount();
      if (rfd.getFailedCount() < 2) {
        rfd.setRetryAfter(FAILED_RETRY_AFTER);
synchronized (this) {
          files.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) {
      LOG.trace("String_Node_Str");
synchronized (this) {
        updateNeeded(dloader);
        files.add(rfd);
      }
      return 0;
    }
synchronized (this) {
      if (!dloaders.contains(dloader))       dloaders.add(dloader);
      chatList.addHost(dloader);
      browseList.addHost(dloader);
    }
    if (RECORD_STATS)     DownloadStat.RESPONSE_OK.incrementStat();
    return 2;
  }
}