Program: 4230
Project: 4230
Buggy source:
/** 
 * Checks whether the given upload may proceed based on number of slots, position in upload queue, etc.  Updates the upload queue as necessary. Always accepts Browse Host requests, though.  Notifies callback of this.
 * @return ACCEPTED if the download may proceed, QUEUED if this is in theupload queue, REJECTED if this is flat-out disallowed (and hence not queued) and BANNED if the downloader is hammering us, and BYPASS_QUEUE if this is a File-View request that isn't hammering us. If REJECTED,  <tt>uploader</tt>'s state will be set to LIMIT_REACHED. If BANNED, the <tt>Uploader</tt>'s state will be set to BANNED_GREEDY.
 * @exception IOException the request came sooner than allowed by uploadqueueing rules.  (Throwing IOException forces the connection to be closed by the calling code.)  
 */
private synchronized int checkAndQueue(HTTPSession session) throws IOException {
  RequestCache rqc=(RequestCache)REQUESTS.get(session.getHost());
  if (rqc == null)   rqc=new RequestCache();
  REQUESTS.put(session.getHost(),rqc);
  rqc.countRequest();
  if (rqc.isHammering()) {
    if (LOG.isWarnEnabled())     LOG.warn(session.getUploader() + "String_Node_Str");
    return BANNED;
  }
  FileDesc fd=session.getUploader().getFileDesc();
  if (!fd.isVerified())   RouterService.getFileManager().validate(fd);
  URN sha1=fd.getSHA1Urn();
  if (rqc.isDupe(sha1))   return REJECTED;
  boolean greedy=rqc.isGreedy(sha1);
  if (slotManager.positionInQueue(session) == -1) {
    if (!greedy && hostLimitReached(session.getHost())) {
      LOG.debug("String_Node_Str");
      greedy=true;
      rqc.limitReached(sha1);
    }
 else     if (greedy && slotManager.getNumQueued() > 0) {
      if (LOG.isDebugEnabled())       LOG.debug(session.getUploader() + "String_Node_Str");
      return REJECTED;
    }
  }
  int queued=slotManager.pollForSlot(session,!greedy && session.getUploader().supportsQueueing());
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + queued);
  if (queued == -1) {
    if (!session.getUploader().supportsQueueing())     slotManager.cancelRequest(session);
    return REJECTED;
  }
  if (queued > 0 && session.poll()) {
    slotManager.cancelRequest(session);
    throw new IOException("String_Node_Str");
  }
  if (queued > 0)   return QUEUED;
 else {
    rqc.startedUpload(sha1);
    return ACCEPTED;
  }
}

Fixed version (ground truth):
/** 
 * Checks whether the given upload may proceed based on number of slots, position in upload queue, etc.  Updates the upload queue as necessary. Always accepts Browse Host requests, though.  Notifies callback of this.
 * @return ACCEPTED if the download may proceed, QUEUED if this is in theupload queue, REJECTED if this is flat-out disallowed (and hence not queued) and BANNED if the downloader is hammering us, and BYPASS_QUEUE if this is a File-View request that isn't hammering us. If REJECTED,  <tt>uploader</tt>'s state will be set to LIMIT_REACHED. If BANNED, the <tt>Uploader</tt>'s state will be set to BANNED_GREEDY.
 * @exception IOException the request came sooner than allowed by uploadqueueing rules.  (Throwing IOException forces the connection to be closed by the calling code.)  
 */
private synchronized int checkAndQueue(HTTPSession session) throws IOException {
  RequestCache rqc=(RequestCache)REQUESTS.get(session.getHost());
  if (rqc == null)   rqc=new RequestCache();
  REQUESTS.put(session.getHost(),rqc);
  rqc.countRequest();
  if (rqc.isHammering()) {
    if (LOG.isWarnEnabled())     LOG.warn(session.getUploader() + "String_Node_Str");
    return BANNED;
  }
  FileDesc fd=session.getUploader().getFileDesc();
  if (!fd.isVerified())   RouterService.getFileManager().validate(fd);
  URN sha1=fd.getSHA1Urn();
  if (rqc.isDupe(sha1))   return REJECTED;
  boolean greedy=rqc.isGreedy(sha1);
  if (slotManager.positionInQueue(session) == -1) {
    if (!greedy && hostLimitReached(session.getHost())) {
      LOG.debug("String_Node_Str");
      greedy=true;
      rqc.limitReached(sha1);
    }
    if (greedy) {
      if (LOG.isDebugEnabled())       LOG.debug(session.getUploader() + "String_Node_Str");
      UploadStat.LIMIT_REACHED_GREEDY.incrementStat();
      return REJECTED;
    }
  }
  int queued=slotManager.pollForSlot(session,session.getUploader().supportsQueueing());
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + queued);
  if (queued == -1) {
    if (!session.getUploader().supportsQueueing())     slotManager.cancelRequest(session);
    return REJECTED;
  }
  if (queued > 0 && session.poll()) {
    slotManager.cancelRequest(session);
    throw new IOException("String_Node_Str");
  }
  if (queued > 0)   return QUEUED;
 else {
    rqc.startedUpload(sha1);
    return ACCEPTED;
  }
}