Program: 4393
Project: 4393
Buggy source:
/** 
 * Sends a GET request using an already open socket, and reads all  headers.  The actual ranges downloaded MAY NOT be the same as the 'start' and 'stop' parameters, as HTTP allows the server to respond with any satisfiable subrange of the request. Users of this class should examine getInitialReadingPoint() and getAmountToRead() to determine what the effective start & stop ranges are, and update external datastructures appropriately. int newStart = dloader.getInitialReadingPoint(); int newStop = (dloader.getAmountToRead() - 1) + newStart; // INCLUSIVE or int newStop = dloader.getAmountToRead() + newStart; // EXCLUSIVE <p>
 * @param start The byte at which the HTTPDownloader should begin
 * @param stop the index just past the last byte to read;stop-1 is the last byte the HTTPDownloader should download <p>
 * @exception TryAgainLaterException the host is busy
 * @exception FileNotFoundException the host doesn't recognize the file
 * @exception NotSharingException the host isn't sharing files (BearShare)
 * @exception IOException miscellaneous  error 
 * @exception QueuedException uploader has queued us
 * @exception RangeNotAvailableException uploader has ranges other than requested
 * @exception ProblemReadingHeaderException could not parse headers
 * @exception UnknownCodeException unknown response code
 */
public void connectHTTP(int start,int stop,boolean supportQueueing) throws IOException, TryAgainLaterException, FileNotFoundException, NotSharingException, QueuedException, RangeNotAvailableException, ProblemReadingHeaderException, UnknownCodeException {
  if (start < 0)   throw new IllegalArgumentException("String_Node_Str" + start);
  if (stop <= start)   throw new IllegalArgumentException("String_Node_Str" + stop + "String_Node_Str"+ start+ "String_Node_Str");
  _amountToRead=stop - start;
  _totalAmountRead+=_amountRead;
  _amountRead=0;
  _initialReadingPoint=start;
  _bodyConsumed=false;
  _contentLength=0;
  Set features=new HashSet();
  OutputStreamWriter osw=new OutputStreamWriter(_output);
  BufferedWriter out=new BufferedWriter(osw);
  String startRange=java.lang.String.valueOf(_initialReadingPoint);
  out.write("String_Node_Str" + _rfd.getUrl().getFile() + "String_Node_Str");
  out.write("String_Node_Str" + _host + "String_Node_Str"+ _port+ "String_Node_Str");
  out.write("String_Node_Str" + CommonUtils.getHttpServer() + "String_Node_Str");
  if (supportQueueing) {
    out.write("String_Node_Str");
    features.add(ConstantHTTPHeaderValue.QUEUE_FEATURE);
  }
  features.add(ConstantHTTPHeaderValue.PUSH_LOCS_FEATURE);
  if (!RouterService.acceptedIncomingConnection() && UDPService.instance().canDoFWT())   features.add(ConstantHTTPHeaderValue.FWT_PUSH_LOCS_FEATURE);
  if (isPartialFileValid() && (RouterService.acceptedIncomingConnection() || _wantsFalts)) {
    AlternateLocation me=AlternateLocation.create(_rfd.getSHA1Urn());
    if (me != null)     addSuccessfulAltLoc(me);
  }
  URN sha1=_rfd.getSHA1Urn();
  if (sha1 != null)   HTTPUtils.writeHeader(HTTPHeaderName.GNUTELLA_CONTENT_URN,sha1,out);
  Set writeClone=null;
synchronized (_goodLocs) {
    if (_goodLocs.size() > 0) {
      writeClone=new HashSet();
      Iterator iter=_goodLocs.iterator();
      while (iter.hasNext()) {
        Object next=iter.next();
        writeClone.add(next);
        _writtenGoodLocs.add(next);
      }
      _goodLocs.clear();
    }
  }
  if (writeClone != null)   HTTPUtils.writeHeader(HTTPHeaderName.ALT_LOCATION,new HTTPHeaderValueCollection(writeClone),out);
  writeClone=null;
synchronized (_badLocs) {
    if (_badLocs.size() > 0) {
      writeClone=new HashSet();
      Iterator iter=_badLocs.iterator();
      while (iter.hasNext()) {
        Object next=iter.next();
        writeClone.add(next);
        _writtenBadLocs.add(next);
      }
      _badLocs.clear();
    }
  }
  if (writeClone != null)   HTTPUtils.writeHeader(HTTPHeaderName.NALTS,new HTTPHeaderValueCollection(writeClone),out);
  if (_wantsFalts) {
    writeClone=null;
synchronized (_goodPushLocs) {
      if (_goodPushLocs.size() > 0) {
        writeClone=new HashSet();
        Iterator iter=_goodPushLocs.iterator();
        while (iter.hasNext()) {
          PushAltLoc next=(PushAltLoc)iter.next();
          if (next.getPushAddress().getProxies().isEmpty()) {
            if (next.getPushAddress() instanceof PushEndpointForSelf)             continue;
 else             Assert.that(false,"String_Node_Str");
          }
          writeClone.add(next);
          _writtenPushLocs.add(next);
        }
        _goodPushLocs.clear();
      }
    }
    if (writeClone != null)     HTTPUtils.writeHeader(HTTPHeaderName.FALT_LOCATION,new HTTPHeaderValueCollection(writeClone),out);
    writeClone=null;
synchronized (_badPushLocs) {
      if (_badPushLocs.size() > 0) {
        writeClone=new HashSet();
        Iterator iter=_badPushLocs.iterator();
        while (iter.hasNext()) {
          PushAltLoc next=(PushAltLoc)iter.next();
          Assert.that(!next.getPushAddress().getProxies().isEmpty());
          writeClone.add(next);
          _writtenBadPushLocs.add(next);
        }
        _badPushLocs.clear();
      }
    }
    if (writeClone != null)     HTTPUtils.writeHeader(HTTPHeaderName.BFALT_LOCATION,new HTTPHeaderValueCollection(writeClone),out);
  }
  out.write("String_Node_Str" + startRange + "String_Node_Str"+ (stop - 1)+ "String_Node_Str");
  _requestedInterval=new Interval(_initialReadingPoint,stop - 1);
  if (ChatSettings.CHAT_ENABLED.getValue() && RouterService.acceptedIncomingConnection() && !NetworkUtils.isPrivateAddress(RouterService.getAddress())) {
    int port=RouterService.getPort();
    String host=NetworkUtils.ip2string(RouterService.getAddress());
    out.write("String_Node_Str" + host + "String_Node_Str"+ port+ "String_Node_Str");
    features.add(ConstantHTTPHeaderValue.BROWSE_FEATURE);
    if (ChatSettings.CHAT_ENABLED.getValue()) {
      out.write("String_Node_Str" + host + "String_Node_Str"+ port+ "String_Node_Str");
      features.add(ConstantHTTPHeaderValue.CHAT_FEATURE);
    }
  }
  if (features.size() > 0) {
    HTTPUtils.writeHeader(HTTPHeaderName.FEATURES,new HTTPHeaderValueCollection(features),out);
  }
  out.write("String_Node_Str");
  out.flush();
  readHeaders();
}

Fixed version (ground truth):
/** 
 * Sends a GET request using an already open socket, and reads all  headers.  The actual ranges downloaded MAY NOT be the same as the 'start' and 'stop' parameters, as HTTP allows the server to respond with any satisfiable subrange of the request. Users of this class should examine getInitialReadingPoint() and getAmountToRead() to determine what the effective start & stop ranges are, and update external datastructures appropriately. int newStart = dloader.getInitialReadingPoint(); int newStop = (dloader.getAmountToRead() - 1) + newStart; // INCLUSIVE or int newStop = dloader.getAmountToRead() + newStart; // EXCLUSIVE <p>
 * @param start The byte at which the HTTPDownloader should begin
 * @param stop the index just past the last byte to read;stop-1 is the last byte the HTTPDownloader should download <p>
 * @exception TryAgainLaterException the host is busy
 * @exception FileNotFoundException the host doesn't recognize the file
 * @exception NotSharingException the host isn't sharing files (BearShare)
 * @exception IOException miscellaneous  error 
 * @exception QueuedException uploader has queued us
 * @exception RangeNotAvailableException uploader has ranges other than requested
 * @exception ProblemReadingHeaderException could not parse headers
 * @exception UnknownCodeException unknown response code
 */
public void connectHTTP(int start,int stop,boolean supportQueueing) throws IOException, TryAgainLaterException, FileNotFoundException, NotSharingException, QueuedException, RangeNotAvailableException, ProblemReadingHeaderException, UnknownCodeException {
  if (start < 0)   throw new IllegalArgumentException("String_Node_Str" + start);
  if (stop <= start)   throw new IllegalArgumentException("String_Node_Str" + stop + "String_Node_Str"+ start+ "String_Node_Str");
  _amountToRead=stop - start;
  _totalAmountRead+=_amountRead;
  _amountRead=0;
  _initialReadingPoint=start;
  _bodyConsumed=false;
  _contentLength=0;
  Set features=new HashSet();
  OutputStreamWriter osw=new OutputStreamWriter(_output);
  BufferedWriter out=new BufferedWriter(osw);
  String startRange=java.lang.String.valueOf(_initialReadingPoint);
  out.write("String_Node_Str" + _rfd.getUrl().getFile() + "String_Node_Str");
  out.write("String_Node_Str" + _host + "String_Node_Str"+ _port+ "String_Node_Str");
  out.write("String_Node_Str" + CommonUtils.getHttpServer() + "String_Node_Str");
  if (supportQueueing) {
    out.write("String_Node_Str");
    features.add(ConstantHTTPHeaderValue.QUEUE_FEATURE);
  }
  if (RouterService.acceptedIncomingConnection() || UDPService.instance().canDoFWT()) {
    features.add(ConstantHTTPHeaderValue.PUSH_LOCS_FEATURE);
    if (!RouterService.acceptedIncomingConnection())     features.add(ConstantHTTPHeaderValue.FWT_PUSH_LOCS_FEATURE);
  }
  if (isPartialFileValid() && (RouterService.acceptedIncomingConnection() || _wantsFalts)) {
    AlternateLocation me=AlternateLocation.create(_rfd.getSHA1Urn());
    if (me != null)     addSuccessfulAltLoc(me);
  }
  URN sha1=_rfd.getSHA1Urn();
  if (sha1 != null)   HTTPUtils.writeHeader(HTTPHeaderName.GNUTELLA_CONTENT_URN,sha1,out);
  Set writeClone=null;
synchronized (_goodLocs) {
    if (_goodLocs.size() > 0) {
      writeClone=new HashSet();
      Iterator iter=_goodLocs.iterator();
      while (iter.hasNext()) {
        Object next=iter.next();
        writeClone.add(next);
        _writtenGoodLocs.add(next);
      }
      _goodLocs.clear();
    }
  }
  if (writeClone != null)   HTTPUtils.writeHeader(HTTPHeaderName.ALT_LOCATION,new HTTPHeaderValueCollection(writeClone),out);
  writeClone=null;
synchronized (_badLocs) {
    if (_badLocs.size() > 0) {
      writeClone=new HashSet();
      Iterator iter=_badLocs.iterator();
      while (iter.hasNext()) {
        Object next=iter.next();
        writeClone.add(next);
        _writtenBadLocs.add(next);
      }
      _badLocs.clear();
    }
  }
  if (writeClone != null)   HTTPUtils.writeHeader(HTTPHeaderName.NALTS,new HTTPHeaderValueCollection(writeClone),out);
  if (_wantsFalts) {
    writeClone=null;
synchronized (_goodPushLocs) {
      if (_goodPushLocs.size() > 0) {
        writeClone=new HashSet();
        Iterator iter=_goodPushLocs.iterator();
        while (iter.hasNext()) {
          PushAltLoc next=(PushAltLoc)iter.next();
          if (next.getPushAddress().getProxies().isEmpty()) {
            if (next.getPushAddress() instanceof PushEndpointForSelf)             continue;
 else             Assert.that(false,"String_Node_Str");
          }
          writeClone.add(next);
          _writtenPushLocs.add(next);
        }
        _goodPushLocs.clear();
      }
    }
    if (writeClone != null)     HTTPUtils.writeHeader(HTTPHeaderName.FALT_LOCATION,new HTTPHeaderValueCollection(writeClone),out);
    writeClone=null;
synchronized (_badPushLocs) {
      if (_badPushLocs.size() > 0) {
        writeClone=new HashSet();
        Iterator iter=_badPushLocs.iterator();
        while (iter.hasNext()) {
          PushAltLoc next=(PushAltLoc)iter.next();
          Assert.that(!next.getPushAddress().getProxies().isEmpty());
          writeClone.add(next);
          _writtenBadPushLocs.add(next);
        }
        _badPushLocs.clear();
      }
    }
    if (writeClone != null)     HTTPUtils.writeHeader(HTTPHeaderName.BFALT_LOCATION,new HTTPHeaderValueCollection(writeClone),out);
  }
  out.write("String_Node_Str" + startRange + "String_Node_Str"+ (stop - 1)+ "String_Node_Str");
  _requestedInterval=new Interval(_initialReadingPoint,stop - 1);
  if (RouterService.acceptedIncomingConnection() && !NetworkUtils.isPrivateAddress(RouterService.getAddress())) {
    int port=RouterService.getPort();
    String host=NetworkUtils.ip2string(RouterService.getAddress());
    out.write("String_Node_Str" + host + "String_Node_Str"+ port+ "String_Node_Str");
    features.add(ConstantHTTPHeaderValue.BROWSE_FEATURE);
    if (ChatSettings.CHAT_ENABLED.getValue()) {
      out.write("String_Node_Str" + host + "String_Node_Str"+ port+ "String_Node_Str");
      features.add(ConstantHTTPHeaderValue.CHAT_FEATURE);
    }
  }
  if (features.size() > 0) {
    HTTPUtils.writeHeader(HTTPHeaderName.FEATURES,new HTTPHeaderValueCollection(features),out);
  }
  out.write("String_Node_Str");
  out.flush();
  readHeaders();
}