Program: 172180
Project: 172180
Buggy source:
private TransferEndEvent transferImpl(String targetName,final TransferDefinition definition,final TransferEventProcessor eventProcessor) throws TransferFailureException {
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + targetName);
  }
  TransferEndEvent endEvent=null;
  Exception failureException=null;
  TransferTarget target=null;
  Transfer transfer=null;
  final List<TransferEvent> transferReportEvents=new LinkedList<TransferEvent>();
  NodeRef sourceReport=null;
  NodeRef destinationReport=null;
  File manifest=null;
  File requisite=null;
  int pollRetries=0;
  int pollPosition=-1;
  boolean cancelled=false;
  TransferCallback reportCallback=new TransferCallback(){
    private static final long serialVersionUID=4072579605731036522L;
    public void processEvent(    TransferEvent event){
      transferReportEvents.add(event);
    }
  }
;
  eventProcessor.addObserver(reportCallback);
  ClientTransferState clientState=ClientTransferState.Begin;
  while (clientState != ClientTransferState.Exit) {
    try {
switch (clientState) {
case Begin:
{
          eventProcessor.start();
          manifest=createManifest(definition);
          logger.debug("String_Node_Str");
          target=getTransferTarget(targetName);
          checkTargetEnabled(target);
          transfer=transmitter.begin(target);
          String transferId=transfer.getTransferId();
          TransferStatus status=new TransferStatus();
          transferMonitoring.put(transferId,status);
          logger.debug("String_Node_Str" + transferId);
          eventProcessor.begin(transferId);
          checkCancel(transferId);
          clientState=ClientTransferState.Prepare;
          break;
        }
case Prepare:
{
        eventProcessor.sendSnapshot(1,1);
        requisite=createRequisiteFile();
        FileOutputStream reqOutput=new FileOutputStream(requisite);
        transmitter.sendManifest(transfer,manifest,reqOutput);
        logger.debug("String_Node_Str");
        checkCancel(transfer.getTransferId());
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str");
          try {
            outputFile(requisite);
          }
 catch (          IOException error) {
            logger.debug("String_Node_Str");
            error.printStackTrace();
          }
        }
        sendContent(transfer,definition,eventProcessor,manifest,requisite);
        logger.debug("String_Node_Str");
        checkCancel(transfer.getTransferId());
        eventProcessor.prepare();
        transmitter.prepare(transfer);
        checkCancel(transfer.getTransferId());
        clientState=ClientTransferState.Commit;
        break;
      }
case Commit:
{
      eventProcessor.commit();
      transmitter.commit(transfer);
      logger.debug("String_Node_Str" + transfer.getTransferId());
      checkCancel(transfer.getTransferId());
      clientState=ClientTransferState.Poll;
      break;
    }
case Poll:
{
    TransferProgress progress=null;
    try {
      progress=transmitter.getStatus(transfer);
      pollRetries=0;
    }
 catch (    TransferException e) {
      pollRetries++;
      if (pollRetries == 3) {
        throw new TransferException(MSG_FAILED_TO_GET_TRANSFER_STATUS,new Object[]{target.getName()});
      }
    }
    if (progress.getCurrentPosition() != pollPosition) {
      pollPosition=progress.getCurrentPosition();
      logger.debug("String_Node_Str" + pollPosition);
      eventProcessor.committing(progress.getEndPosition(),pollPosition);
    }
    if (progress.getStatus() == TransferProgress.Status.ERROR) {
      Throwable targetError=progress.getError();
      if (targetError == null) {
        targetError=new TransferException(MSG_UNKNOWN_TARGET_ERROR);
      }
      if (Exception.class.isAssignableFrom(targetError.getClass())) {
        failureException=(Exception)targetError;
      }
 else {
        failureException=new TransferException(MSG_TARGET_ERROR,new Object[]{targetError.getMessage()},targetError);
      }
      clientState=ClientTransferState.Finished;
      break;
    }
 else     if (progress.getStatus() == TransferProgress.Status.CANCELLED) {
      cancelled=true;
      clientState=ClientTransferState.Finished;
      break;
    }
 else     if (progress.getStatus() == TransferProgress.Status.COMPLETE) {
      clientState=ClientTransferState.Finished;
      break;
    }
    checkCancel(transfer.getTransferId());
    try {
      Thread.sleep(commitPollDelay);
    }
 catch (    InterruptedException e) {
    }
    break;
  }
case Cancel:
{
  logger.debug("String_Node_Str");
  transmitter.abort(transfer);
  clientState=ClientTransferState.Poll;
  break;
}
case Finished:
{
try {
  TransferEndEventImpl endEventImpl=null;
  String reportName=null;
  try {
    if (failureException != null) {
      logger.debug("String_Node_Str",failureException);
      TransferEventError errorEvent=new TransferEventError();
      errorEvent.setTransferState(TransferEvent.TransferState.ERROR);
      errorEvent.setException(failureException);
      errorEvent.setMessage(failureException.getMessage());
      endEventImpl=errorEvent;
      reportName="String_Node_Str";
    }
 else     if (cancelled) {
      endEventImpl=new TransferEventCancelled();
      endEventImpl.setTransferState(TransferEvent.TransferState.CANCELLED);
      endEventImpl.setMessage("String_Node_Str");
      reportName="String_Node_Str";
    }
 else {
      logger.debug("String_Node_Str" + transfer.getTransferId());
      endEventImpl=new TransferEventSuccess();
      endEventImpl.setTransferState(TransferEvent.TransferState.SUCCESS);
      endEventImpl.setMessage("String_Node_Str");
      reportName="String_Node_Str";
    }
    transferReportEvents.add(endEventImpl);
  }
 catch (  Exception e) {
    failureException=e;
    reportName="String_Node_Str";
    logger.warn("String_Node_Str",e);
  }
  reportName+="String_Node_Str" + new SimpleDateFormat("String_Node_Str").format(new Date());
  try {
    if (transfer != null) {
      logger.debug("String_Node_Str");
      destinationReport=persistDestinationTransferReport(reportName,transfer,target);
      if (destinationReport != null) {
        eventProcessor.writeReport(destinationReport,TransferEventReport.ReportType.DESTINATION,endEventImpl.getTransferState());
      }
    }
    logger.debug("String_Node_Str");
    sourceReport=persistTransferReport(reportName,transfer,target,definition,transferReportEvents,manifest,failureException);
    if (sourceReport != null) {
      eventProcessor.writeReport(sourceReport,TransferEventReport.ReportType.SOURCE,endEventImpl.getTransferState());
    }
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str",e);
  }
  try {
    endEventImpl.setLast(true);
    endEventImpl.setSourceReport(sourceReport);
    endEventImpl.setDestinationReport(destinationReport);
    endEvent=endEventImpl;
    eventProcessor.end(endEvent);
  }
 catch (  Exception e) {
    failureException=e;
    logger.warn("String_Node_Str",e);
  }
}
  finally {
  clientState=ClientTransferState.Exit;
}
}
}
}
 catch (TransferCancelledException e) {
logger.debug("String_Node_Str");
clientState=ClientTransferState.Cancel;
}
catch (Exception e) {
logger.debug("String_Node_Str",e);
failureException=e;
clientState=ClientTransferState.Finished;
}
}
try {
if (endEvent == null) {
TransferEventError error=new TransferEventError();
error.setTransferState(TransferEvent.TransferState.ERROR);
TransferFailureException endException=new TransferFailureException(error);
error.setMessage(endException.getMessage());
error.setException(endException);
error.setSourceReport(sourceReport);
error.setDestinationReport(destinationReport);
error.setLast(true);
endEvent=error;
}
if (endEvent instanceof TransferEventError) {
TransferEventError endError=(TransferEventError)endEvent;
throw new TransferFailureException(endError);
}
return endEvent;
}
  finally {
if (transfer != null) {
transferMonitoring.remove(transfer.getTransferId());
}
if (manifest != null) {
manifest.delete();
logger.debug("String_Node_Str");
}
if (requisite != null) {
requisite.delete();
logger.debug("String_Node_Str");
}
}
}

Fixed version (ground truth):
private TransferEndEvent transferImpl(String targetName,final TransferDefinition definition,final TransferEventProcessor eventProcessor) throws TransferFailureException {
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + targetName);
  }
  TransferEndEvent endEvent=null;
  Exception failureException=null;
  TransferTarget target=null;
  Transfer transfer=null;
  final List<TransferEvent> transferReportEvents=new LinkedList<TransferEvent>();
  NodeRef sourceReport=null;
  NodeRef destinationReport=null;
  File manifest=null;
  File requisite=null;
  int pollRetries=0;
  int pollPosition=-1;
  boolean cancelled=false;
  TransferCallback reportCallback=new TransferCallback(){
    private static final long serialVersionUID=4072579605731036522L;
    public void processEvent(    TransferEvent event){
      transferReportEvents.add(event);
    }
  }
;
  eventProcessor.addObserver(reportCallback);
  ClientTransferState clientState=ClientTransferState.Begin;
  while (clientState != ClientTransferState.Exit) {
    try {
switch (clientState) {
case Begin:
{
          eventProcessor.start();
          manifest=createManifest(definition);
          logger.debug("String_Node_Str");
          target=getTransferTarget(targetName);
          checkTargetEnabled(target);
          transfer=transmitter.begin(target);
          String transferId=transfer.getTransferId();
          TransferStatus status=new TransferStatus();
          transferMonitoring.put(transferId,status);
          logger.debug("String_Node_Str" + transferId);
          eventProcessor.begin(transferId);
          checkCancel(transferId);
          clientState=ClientTransferState.Prepare;
          break;
        }
case Prepare:
{
        eventProcessor.sendSnapshot(1,1);
        requisite=createRequisiteFile();
        FileOutputStream reqOutput=new FileOutputStream(requisite);
        transmitter.sendManifest(transfer,manifest,reqOutput);
        logger.debug("String_Node_Str");
        checkCancel(transfer.getTransferId());
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str");
          try {
            outputFile(requisite);
          }
 catch (          IOException error) {
            logger.debug("String_Node_Str");
            error.printStackTrace();
          }
        }
        sendContent(transfer,definition,eventProcessor,manifest,requisite);
        logger.debug("String_Node_Str");
        checkCancel(transfer.getTransferId());
        eventProcessor.prepare();
        transmitter.prepare(transfer);
        checkCancel(transfer.getTransferId());
        clientState=ClientTransferState.Commit;
        break;
      }
case Commit:
{
      eventProcessor.commit();
      transmitter.commit(transfer);
      logger.debug("String_Node_Str" + transfer.getTransferId());
      checkCancel(transfer.getTransferId());
      clientState=ClientTransferState.Poll;
      break;
    }
case Poll:
{
    TransferProgress progress=null;
    try {
      progress=transmitter.getStatus(transfer);
      pollRetries=0;
    }
 catch (    TransferException e) {
      pollRetries++;
      if (pollRetries == 3) {
        throw new TransferException(MSG_FAILED_TO_GET_TRANSFER_STATUS,new Object[]{target.getName()});
      }
    }
    if (progress.getStatus() == TransferProgress.Status.ERROR) {
      Throwable targetError=progress.getError();
      if (targetError == null) {
        targetError=new TransferException(MSG_UNKNOWN_TARGET_ERROR);
      }
      if (Exception.class.isAssignableFrom(targetError.getClass())) {
        failureException=(Exception)targetError;
      }
 else {
        failureException=new TransferException(MSG_TARGET_ERROR,new Object[]{targetError.getMessage()},targetError);
      }
      clientState=ClientTransferState.Finished;
      break;
    }
 else     if (progress.getStatus() == TransferProgress.Status.CANCELLED) {
      cancelled=true;
      clientState=ClientTransferState.Finished;
      break;
    }
    if (progress.getCurrentPosition() != pollPosition) {
      pollPosition=progress.getCurrentPosition();
      logger.debug("String_Node_Str" + pollPosition);
      eventProcessor.committing(progress.getEndPosition(),pollPosition);
    }
    if (progress.getStatus() == TransferProgress.Status.COMPLETE) {
      clientState=ClientTransferState.Finished;
      break;
    }
    checkCancel(transfer.getTransferId());
    try {
      Thread.sleep(commitPollDelay);
    }
 catch (    InterruptedException e) {
    }
    break;
  }
case Cancel:
{
  logger.debug("String_Node_Str");
  transmitter.abort(transfer);
  clientState=ClientTransferState.Poll;
  break;
}
case Finished:
{
try {
  TransferEndEventImpl endEventImpl=null;
  String reportName=null;
  try {
    if (failureException != null) {
      logger.debug("String_Node_Str",failureException);
      TransferEventError errorEvent=new TransferEventError();
      errorEvent.setTransferState(TransferEvent.TransferState.ERROR);
      errorEvent.setException(failureException);
      errorEvent.setMessage(failureException.getMessage());
      endEventImpl=errorEvent;
      reportName="String_Node_Str";
    }
 else     if (cancelled) {
      endEventImpl=new TransferEventCancelled();
      endEventImpl.setTransferState(TransferEvent.TransferState.CANCELLED);
      endEventImpl.setMessage("String_Node_Str");
      reportName="String_Node_Str";
    }
 else {
      logger.debug("String_Node_Str" + transfer.getTransferId());
      endEventImpl=new TransferEventSuccess();
      endEventImpl.setTransferState(TransferEvent.TransferState.SUCCESS);
      endEventImpl.setMessage("String_Node_Str");
      reportName="String_Node_Str";
    }
    transferReportEvents.add(endEventImpl);
  }
 catch (  Exception e) {
    failureException=e;
    reportName="String_Node_Str";
    logger.warn("String_Node_Str",e);
  }
  reportName+="String_Node_Str" + new SimpleDateFormat("String_Node_Str").format(new Date());
  try {
    if (transfer != null) {
      logger.debug("String_Node_Str");
      destinationReport=persistDestinationTransferReport(reportName,transfer,target);
      if (destinationReport != null) {
        eventProcessor.writeReport(destinationReport,TransferEventReport.ReportType.DESTINATION,endEventImpl.getTransferState());
      }
    }
    logger.debug("String_Node_Str");
    sourceReport=persistTransferReport(reportName,transfer,target,definition,transferReportEvents,manifest,failureException);
    if (sourceReport != null) {
      eventProcessor.writeReport(sourceReport,TransferEventReport.ReportType.SOURCE,endEventImpl.getTransferState());
    }
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str",e);
  }
  try {
    endEventImpl.setLast(true);
    endEventImpl.setSourceReport(sourceReport);
    endEventImpl.setDestinationReport(destinationReport);
    endEvent=endEventImpl;
    eventProcessor.end(endEvent);
  }
 catch (  Exception e) {
    failureException=e;
    logger.warn("String_Node_Str",e);
  }
}
  finally {
  clientState=ClientTransferState.Exit;
}
}
}
}
 catch (TransferCancelledException e) {
logger.debug("String_Node_Str");
clientState=ClientTransferState.Cancel;
}
catch (Exception e) {
logger.debug("String_Node_Str",e);
failureException=e;
if (transfer != null && (clientState == ClientTransferState.Begin || clientState == ClientTransferState.Prepare)) {
clientState=ClientTransferState.Cancel;
}
 else {
clientState=ClientTransferState.Finished;
}
}
}
try {
if (endEvent == null) {
TransferEventError error=new TransferEventError();
error.setTransferState(TransferEvent.TransferState.ERROR);
TransferFailureException endException=new TransferFailureException(error);
error.setMessage(endException.getMessage());
error.setException(endException);
error.setSourceReport(sourceReport);
error.setDestinationReport(destinationReport);
error.setLast(true);
endEvent=error;
}
if (endEvent instanceof TransferEventError) {
TransferEventError endError=(TransferEventError)endEvent;
throw new TransferFailureException(endError);
}
return endEvent;
}
  finally {
if (transfer != null) {
transferMonitoring.remove(transfer.getTransferId());
}
if (manifest != null) {
manifest.delete();
logger.debug("String_Node_Str");
}
if (requisite != null) {
requisite.delete();
logger.debug("String_Node_Str");
}
}
}