Program: 105323
Project: 105323
Buggy source:
private boolean manageApplication(SecurityPolicyType type,SrxCommand command,Protocol protocol,int startPort,int endPort) throws ExecutionException {
  if (protocol.equals(Protocol.any)) {
    return true;
  }
  String applicationName=genApplicationName(type,protocol,startPort,endPort);
  String xml;
switch (command) {
case CHECK_IF_EXISTS:
    xml=SrxXml.APPLICATION_GETONE.getXml();
  xml=setDelete(xml,false);
xml=replaceXmlValue(xml,"String_Node_Str",applicationName);
return sendRequestAndCheckResponse(command,xml,"String_Node_Str",applicationName);
case ADD:
if (manageApplication(type,SrxCommand.CHECK_IF_EXISTS,protocol,startPort,endPort)) {
return true;
}
String icmpOrDestPort;
xml=SrxXml.APPLICATION_ADD.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",applicationName);
xml=replaceXmlValue(xml,"String_Node_Str",protocol.toString());
if (protocol.toString() == Protocol.icmp.toString()) {
icmpOrDestPort="String_Node_Str" + startPort + "String_Node_Str";
icmpOrDestPort+="String_Node_Str" + endPort + "String_Node_Str";
}
 else {
String destPort;
if (startPort == endPort) {
destPort=String.valueOf(startPort);
}
 else {
destPort=startPort + "String_Node_Str" + endPort;
}
icmpOrDestPort="String_Node_Str" + destPort + "String_Node_Str";
}
xml=replaceXmlValue(xml,"String_Node_Str",icmpOrDestPort);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str" + applicationName);
}
 else {
return true;
}
case DELETE:
if (!manageApplication(type,SrxCommand.CHECK_IF_EXISTS,protocol,startPort,endPort)) {
return true;
}
xml=SrxXml.APPLICATION_GETONE.getXml();
xml=setDelete(xml,true);
xml=replaceXmlValue(xml,"String_Node_Str",applicationName);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str" + applicationName);
}
 else {
return true;
}
default :
s_logger.debug("String_Node_Str");
return false;
}
}

Fixed version (ground truth):
private boolean manageApplication(SecurityPolicyType type,SrxCommand command,Protocol protocol,int startPort,int endPort) throws ExecutionException {
  if (protocol.equals(Protocol.any)) {
    return true;
  }
  String applicationName=genApplicationName(type,protocol,startPort,endPort);
  String xml;
switch (command) {
case CHECK_IF_EXISTS:
    xml=SrxXml.APPLICATION_GETONE.getXml();
  xml=setDelete(xml,false);
xml=replaceXmlValue(xml,"String_Node_Str",applicationName);
return sendRequestAndCheckResponse(command,xml,"String_Node_Str",applicationName);
case ADD:
if (manageApplication(type,SrxCommand.CHECK_IF_EXISTS,protocol,startPort,endPort)) {
return true;
}
String icmpOrDestPort;
xml=SrxXml.APPLICATION_ADD.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",applicationName);
xml=replaceXmlValue(xml,"String_Node_Str",protocol.toString());
if (protocol.toString().equals(Protocol.icmp.toString())) {
icmpOrDestPort="String_Node_Str" + startPort + "String_Node_Str";
icmpOrDestPort+="String_Node_Str" + endPort + "String_Node_Str";
}
 else {
String destPort;
if (startPort == endPort) {
destPort=String.valueOf(startPort);
}
 else {
destPort=startPort + "String_Node_Str" + endPort;
}
icmpOrDestPort="String_Node_Str" + destPort + "String_Node_Str";
}
xml=replaceXmlValue(xml,"String_Node_Str",icmpOrDestPort);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str" + applicationName);
}
 else {
return true;
}
case DELETE:
if (!manageApplication(type,SrxCommand.CHECK_IF_EXISTS,protocol,startPort,endPort)) {
return true;
}
xml=SrxXml.APPLICATION_GETONE.getXml();
xml=setDelete(xml,true);
xml=replaceXmlValue(xml,"String_Node_Str",applicationName);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str" + applicationName);
}
 else {
return true;
}
default :
s_logger.debug("String_Node_Str");
return false;
}
}