Program: 4983
Project: 4983
Buggy source:
/** 
 * This class implements a succesful upload version of the doUpload method.  It prepares a file, writes the appropriate header, then sends the file.
 */
public void doUpload(HTTPUploader uploader) throws IOException {
  try {
    _uploader=uploader;
    _uploader.setState(_uploader.UPLOADING);
    _ostream=_uploader.getOutputStream();
    _index=_uploader.getIndex();
    _filename=_uploader.getFileName();
    _fileSize=_uploader.getFileSize();
    _fis=_uploader.getInputStream();
    _amountRead=_uploader.amountUploaded();
    _uploadBegin=_uploader.getUploadBegin();
    _uploadEnd=_uploader.getUploadEnd();
    if (_fileSize < _uploadBegin)     return;
    if (_uploadEnd <= 0 || _uploadEnd <= _uploadBegin || _uploadEnd > _fileSize)     _uploadEnd=_fileSize;
    writeHeader();
    int c=-1;
    int available=0;
    byte[] buf=new byte[1024];
    long a=_fis.skip(_uploadBegin);
    _amountRead+=a;
    _uploader.setAmountUploaded(_amountRead);
    SettingsManager manager=SettingsManager.instance();
    int speed=manager.getUploadSpeed();
    if (speed == 100) {
      while (true) {
        c=_fis.read(buf);
        if (c == -1)         break;
        if (c > (_uploadEnd - _amountRead))         c=_uploadEnd - _amountRead;
        try {
          _ostream.write(buf,0,c);
        }
 catch (        java.net.SocketException e) {
          throw new IOException();
        }
        _amountRead+=c;
        _uploader.setAmountUploaded(_amountRead);
        if (_amountRead >= _uploadEnd)         break;
      }
    }
 else {
      while (true) {
        int max=_uploader.getManager().calculateBandwidth();
        int burstSize=max * CYCLE_TIME;
        int burstSent=0;
        long start=System.currentTimeMillis();
        while (burstSent < burstSize) {
          c=_fis.read(buf);
          if (c == -1)           return;
          if (c > (_uploadEnd - _amountRead))           c=_uploadEnd - _amountRead;
          try {
            _ostream.write(buf,0,c);
          }
 catch (          java.net.SocketException e) {
            throw new IOException();
          }
          _amountRead+=c;
          _uploader.setAmountUploaded(_amountRead);
          burstSent+=c;
          if (_amountRead >= _uploadEnd)           break;
        }
        long stop=System.currentTimeMillis();
        int elapsed=(int)(stop - start);
        int sleepTime=CYCLE_TIME - elapsed;
        if (sleepTime > 0) {
          try {
            Thread.currentThread().sleep(sleepTime);
          }
 catch (          InterruptedException e) {
            throw new IOException();
          }
        }
      }
    }
  }
 catch (  IOException ioe) {
    _closeConnection=true;
    throw ioe;
  }
}

Fixed version (ground truth):
/** 
 * This class implements a succesful upload version of the doUpload method.  It prepares a file, writes the appropriate header, then sends the file.
 */
public void doUpload(HTTPUploader uploader) throws IOException {
  try {
    _uploader=uploader;
    _uploader.setState(_uploader.UPLOADING);
    _ostream=_uploader.getOutputStream();
    _index=_uploader.getIndex();
    _filename=_uploader.getFileName();
    _fileSize=_uploader.getFileSize();
    _fis=_uploader.getInputStream();
    _amountRead=_uploader.amountUploaded();
    _uploadBegin=_uploader.getUploadBegin();
    _uploadEnd=_uploader.getUploadEnd();
    if (_fileSize < _uploadBegin)     return;
    if (_uploadEnd <= 0 || _uploadEnd <= _uploadBegin || _uploadEnd > _fileSize)     _uploadEnd=_fileSize;
    writeHeader();
    int c=-1;
    int available=0;
    byte[] buf=new byte[1024];
    long a=_fis.skip(_uploadBegin);
    _amountRead+=a;
    _uploader.setAmountUploaded(_amountRead);
    SettingsManager manager=SettingsManager.instance();
    int speed=manager.getUploadSpeed();
    if (speed == 100) {
      while (true) {
        c=_fis.read(buf);
        if (c == -1)         break;
        if (c > (_uploadEnd - _amountRead))         c=_uploadEnd - _amountRead;
        try {
          _ostream.write(buf,0,c);
        }
 catch (        java.net.SocketException e) {
          throw new IOException();
        }
        _amountRead+=c;
        _uploader.setAmountUploaded(_amountRead);
        if (_amountRead >= _uploadEnd)         break;
      }
    }
 else {
      while (true) {
        int max=_uploader.getManager().calculateBandwidth();
        int burstSize=max * CYCLE_TIME;
        int burstSent=0;
        long start=System.currentTimeMillis();
        while (burstSent < burstSize) {
          c=_fis.read(buf);
          if (c == -1)           return;
          if (c > (_uploadEnd - _amountRead))           c=_uploadEnd - _amountRead;
          try {
            _ostream.write(buf,0,c);
          }
 catch (          java.net.SocketException e) {
            throw new IOException();
          }
          _amountRead+=c;
          _uploader.setAmountUploaded(_amountRead);
          burstSent+=c;
          if (_amountRead >= _uploadEnd)           break;
        }
        long stop=System.currentTimeMillis();
        int elapsed=(int)(stop - start);
        int sleepTime=CYCLE_TIME - elapsed;
        if (sleepTime > 0) {
          try {
            Thread.currentThread().sleep(sleepTime);
          }
 catch (          InterruptedException e) {
            throw new IOException();
          }
        }
      }
    }
  }
 catch (  IOException ioe) {
    _closeConnection=true;
    throw ioe;
  }
  _uploader.setState(_uploader.COMPLETE);
}