Program: 34425
Project: 34425
Buggy source:
/** 
 * A sample method that downloads a firmware image from a HTTP server
 */
@Override public void downloadFirmware(DeviceFirmware deviceFirmware){
  System.out.println(CLASS_NAME + "String_Node_Str" + deviceFirmware.getDeviceId());
  boolean success=false;
  URL firmwareURL=null;
  URLConnection urlConnection=null;
  String downloadedFirmwareName="String_Node_Str";
  DeviceInterface device=this.deviceMap.get(deviceFirmware.getDeviceId());
  try {
    System.out.println(CLASS_NAME + "String_Node_Str" + deviceFirmware.getUrl());
    firmwareURL=new URL(deviceFirmware.getUrl());
    urlConnection=firmwareURL.openConnection();
    if (deviceFirmware.getName() != null && !"String_Node_Str".equals(deviceFirmware.getName())) {
      downloadedFirmwareName=deviceFirmware.getName();
    }
 else {
      downloadedFirmwareName=deviceFirmware.getDeviceId() + "String_Node_Str" + new Date().getTime()+ "String_Node_Str";
    }
    File file=new File(downloadedFirmwareName);
    BufferedInputStream bis=new BufferedInputStream(urlConnection.getInputStream());
    BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file.getName()));
    int data=bis.read();
    if (data != -1) {
      bos.write(data);
      byte[] block=new byte[1024];
      while (true) {
        int len=bis.read(block,0,block.length);
        if (len != -1) {
          bos.write(block,0,len);
        }
 else {
          break;
        }
      }
      bos.close();
      bis.close();
      success=true;
    }
 else {
      deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.INVALID_URI);
    }
    if (deviceFirmware.getVerifier() != null && !deviceFirmware.getVerifier().equals("String_Node_Str")) {
      success=verifyFirmware(file,deviceFirmware.getVerifier());
      if (success == false) {
        deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.VERIFICATION_FAILED);
      }
    }
  }
 catch (  MalformedURLException me) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.INVALID_URI);
    me.printStackTrace();
  }
catch (  IOException e) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.CONNECTION_LOST);
    e.printStackTrace();
  }
catch (  OutOfMemoryError oom) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.OUT_OF_MEMORY);
  }
  if (success == true) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.SUCCESS);
    deviceFirmware.setState(FirmwareState.DOWNLOADED);
    if (device != null) {
      device.setFirmwareName(downloadedFirmwareName);
    }
 else {
      gatewayDownloadFirmwareName=downloadedFirmwareName;
    }
  }
 else {
    deviceFirmware.setState(FirmwareState.IDLE);
  }
  System.out.println(CLASS_NAME + "String_Node_Str" + success+ "String_Node_Str");
}

Fixed version (ground truth):
/** 
 * A sample method that downloads a firmware image from a HTTP server
 */
@Override public void downloadFirmware(DeviceFirmware deviceFirmware){
  System.out.println(CLASS_NAME + "String_Node_Str" + deviceFirmware.getDeviceId());
  boolean success=false;
  URL firmwareURL=null;
  URLConnection urlConnection=null;
  String downloadedFirmwareName="String_Node_Str";
  DeviceInterface device=this.deviceMap.get(deviceFirmware.getDeviceId());
  try {
    System.out.println(CLASS_NAME + "String_Node_Str" + deviceFirmware.getUrl());
    firmwareURL=new URL(deviceFirmware.getUrl());
    urlConnection=firmwareURL.openConnection();
    int fileSize=urlConnection.getContentLength();
    if (deviceFirmware.getName() != null && !"String_Node_Str".equals(deviceFirmware.getName())) {
      downloadedFirmwareName=deviceFirmware.getName();
    }
 else {
      downloadedFirmwareName=deviceFirmware.getDeviceId() + "String_Node_Str" + new Date().getTime()+ "String_Node_Str";
    }
    File file=new File(downloadedFirmwareName);
    BufferedInputStream bis=new BufferedInputStream(urlConnection.getInputStream());
    BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file.getName()));
    int downloadedSize=0;
    int data=bis.read();
    downloadedSize+=1;
    if (data != -1) {
      bos.write(data);
      byte[] block=new byte[1024];
      while (true) {
        int len=bis.read(block,0,block.length);
        downloadedSize+=len;
        if (fileSize > 0) {
          int progress=(int)(((float)downloadedSize / fileSize) * 100);
          String message="String_Node_Str" + progress + "String_Node_Str";
          if (device != null) {
            device.sendLog(message,new Date(),LogSeverity.informational);
          }
 else {
            gateway.addGatewayLog(message,new Date(),LogSeverity.informational);
          }
          System.out.println(message);
        }
 else {
          String message="String_Node_Str" + downloadedSize + "String_Node_Str";
          if (device != null) {
            device.sendLog(message,new Date(),LogSeverity.informational);
          }
 else {
            gateway.addGatewayLog(message,new Date(),LogSeverity.informational);
          }
          System.out.println(message);
        }
        if (len != -1) {
          bos.write(block,0,len);
        }
 else {
          break;
        }
      }
      bos.close();
      bis.close();
      success=true;
    }
 else {
      deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.INVALID_URI);
    }
    if (deviceFirmware.getVerifier() != null && !deviceFirmware.getVerifier().equals("String_Node_Str")) {
      success=verifyFirmware(file,deviceFirmware.getVerifier());
      if (success == false) {
        deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.VERIFICATION_FAILED);
      }
    }
  }
 catch (  MalformedURLException me) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.INVALID_URI);
    me.printStackTrace();
  }
catch (  IOException e) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.CONNECTION_LOST);
    e.printStackTrace();
  }
catch (  OutOfMemoryError oom) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.OUT_OF_MEMORY);
  }
  if (success == true) {
    deviceFirmware.setUpdateStatus(FirmwareUpdateStatus.SUCCESS);
    deviceFirmware.setState(FirmwareState.DOWNLOADED);
    if (device != null) {
      device.setFirmwareName(downloadedFirmwareName);
    }
 else {
      gatewayDownloadFirmwareName=downloadedFirmwareName;
    }
  }
 else {
    deviceFirmware.setState(FirmwareState.IDLE);
  }
  System.out.println(CLASS_NAME + "String_Node_Str" + success+ "String_Node_Str");
}