Program: 41458
Project: 41458
Buggy source:
/** 
 * Appends BPEL Code that updates InstanceData for the given NodeTemplate. Needs initialization code on the global level in the plan. This will be checked and appended if needed.
 * @param context the TemplateContext of the NodeTemplate
 * @param nodeTemplate the NodeTemplate to handle
 * @return true iff appending all BPEL code was successful
 */
public boolean handleBuild(final BPELPlanContext context,final AbstractNodeTemplate nodeTemplate){
  final boolean hasProps=checkProperties(nodeTemplate.getProperties());
  final String serviceInstanceVarName=context.getServiceInstanceURLVarName();
  if (serviceInstanceVarName == null) {
    return false;
  }
  final String serviceInstanceIDVarName=context.getServiceInstanceIDVarName();
  if (serviceInstanceIDVarName == null) {
    return false;
  }
  final String instanceDataAPIVarName=context.getServiceTemplateURLVar();
  if (instanceDataAPIVarName == null) {
    return false;
  }
  final String restCallResponseVarName=createRESTResponseVar(context);
  if (restCallResponseVarName == null) {
    return false;
  }
  final String stateVarName=createStateVar(context,context.getNodeTemplate().getId());
  if (stateVarName == null) {
    return false;
  }
  try {
    final String bpelString=this.fragments.generateBPEL4RESTLightNodeInstancePOST(instanceDataAPIVarName,serviceInstanceIDVarName,context.getNodeTemplate().getId(),restCallResponseVarName);
    Node createNodeInstanceExActiv=ModelUtils.string2dom(bpelString);
    createNodeInstanceExActiv=context.importNode(createNodeInstanceExActiv);
    context.getPrePhaseElement().appendChild(createNodeInstanceExActiv);
  }
 catch (  final IOException e2) {
    e2.printStackTrace();
  }
catch (  final SAXException e) {
    e.printStackTrace();
  }
catch (  final ParserConfigurationException e) {
    e.printStackTrace();
  }
  String nodeInstanceURLVarName="String_Node_Str";
  if (context.findInstanceURLVar(context.getNodeTemplate().getId(),true) == null) {
    nodeInstanceURLVarName=createInstanceURLVar(context,context.getNodeTemplate().getId());
  }
 else {
    nodeInstanceURLVarName=context.findInstanceURLVar(context.getNodeTemplate().getId(),true);
  }
  if (nodeInstanceURLVarName == null) {
    return false;
  }
  String nodeInstanceIDVarName="String_Node_Str";
  if (context.findInstanceIDVar(context.getNodeTemplate().getId(),true) == null) {
    nodeInstanceIDVarName=createInstanceIDVar(context,context.getNodeTemplate().getId());
  }
 else {
    nodeInstanceIDVarName=context.findInstanceIDVar(context.getNodeTemplate().getId(),true);
  }
  if (nodeInstanceIDVarName == null) {
    return false;
  }
  try {
    final String bpelString=this.fragments.generateAssignFromNodeInstancePOSTResponseToStringVar(nodeInstanceURLVarName,nodeInstanceIDVarName,restCallResponseVarName);
    Node assignNodeInstanceUrl=ModelUtils.string2dom(bpelString);
    assignNodeInstanceUrl=context.importNode(assignNodeInstanceUrl);
    context.getPrePhaseElement().appendChild(assignNodeInstanceUrl);
  }
 catch (  final IOException e2) {
    e2.printStackTrace();
  }
catch (  final SAXException e) {
    e.printStackTrace();
  }
catch (  final ParserConfigurationException e) {
    e.printStackTrace();
  }
  try {
    final BPELProcessFragments frag=new BPELProcessFragments();
    Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + System.currentTimeMillis(),"String_Node_Str",stateVarName);
    assignNode=context.importNode(assignNode);
    context.getPrePhaseElement().appendChild(assignNode);
    final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
    Node extActiv=ModelUtils.string2dom(bpelString);
    extActiv=context.importNode(extActiv);
    context.getPrePhaseElement().appendChild(extActiv);
  }
 catch (  final IOException e2) {
    e2.printStackTrace();
  }
catch (  final SAXException e) {
    e.printStackTrace();
  }
catch (  final ParserConfigurationException e) {
    e.printStackTrace();
  }
  String lastSetState="String_Node_Str";
  final Element provisioningPhaseElement=context.getProvisioningPhaseElement();
  final List<Element> assignContentElements=fetchInvokerCallAssigns(provisioningPhaseElement);
  final List<String> operationNames=new ArrayList<>();
  for (  final Element assignContentElement : assignContentElements) {
    final String operationName=fetchOperationName(assignContentElement);
    operationNames.add(operationName);
    final String preState=InstanceStates.getOperationPreState(operationName);
    final String postState=InstanceStates.getOperationPostState(operationName);
    if (preState != null) {
      try {
        final BPELProcessFragments frag=new BPELProcessFragments();
        Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + operationName + "String_Node_Str"+ System.currentTimeMillis(),"String_Node_Str" + preState + "String_Node_Str",stateVarName);
        assignNode=context.importNode(assignNode);
        lastSetState=preState;
        final Node bpelAssignNode=assignContentElement.getParentNode().getParentNode().getParentNode().getParentNode();
        bpelAssignNode.getParentNode().insertBefore(assignNode,bpelAssignNode);
        final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
        Node extActiv=ModelUtils.string2dom(bpelString);
        extActiv=context.importNode(extActiv);
        bpelAssignNode.getParentNode().insertBefore(extActiv,bpelAssignNode);
      }
 catch (      final IOException e2) {
        e2.printStackTrace();
      }
catch (      final SAXException e) {
        e.printStackTrace();
      }
catch (      final ParserConfigurationException e) {
        e.printStackTrace();
      }
    }
    if (postState != null) {
      try {
        final BPELProcessFragments frag=new BPELProcessFragments();
        Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + operationName + "String_Node_Str"+ System.currentTimeMillis(),"String_Node_Str" + postState + "String_Node_Str",stateVarName);
        assignNode=context.importNode(assignNode);
        lastSetState=postState;
        final Node bpelAssignNode=assignContentElement.getParentNode().getParentNode().getParentNode().getParentNode();
        final String reqVarName=fetchRequestVarNameFromInvokerAssign(assignContentElement);
        final Element invokerReceiveElement=fetchInvokerReceive((Element)bpelAssignNode,reqVarName);
        assignNode=invokerReceiveElement.getParentNode().insertBefore(assignNode,invokerReceiveElement.getNextSibling());
        final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
        Node extActiv=ModelUtils.string2dom(bpelString);
        extActiv=context.importNode(extActiv);
        final Element afterElement=(Element)invokerReceiveElement.getParentNode().insertBefore(extActiv,assignNode.getNextSibling());
        appendUpdateProperties(context,nodeTemplate,nodeInstanceURLVarName,restCallResponseVarName,afterElement.getParentNode());
      }
 catch (      final IOException e2) {
        e2.printStackTrace();
      }
catch (      final SAXException e) {
        e.printStackTrace();
      }
catch (      final ParserConfigurationException e) {
        e.printStackTrace();
      }
    }
  }
  if (lastSetState.equals("String_Node_Str")) {
    try {
      String nextState=InstanceStates.getNextStableOperationState(lastSetState);
      if (operationNames.isEmpty()) {
        nextState="String_Node_Str";
      }
      final BPELProcessFragments frag=new BPELProcessFragments();
      Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + System.currentTimeMillis(),"String_Node_Str" + nextState + "String_Node_Str",stateVarName);
      assignNode=context.importNode(assignNode);
      final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
      Node extActiv=ModelUtils.string2dom(bpelString);
      extActiv=context.importNode(extActiv);
      context.getPostPhaseElement().appendChild(assignNode);
      context.getPostPhaseElement().appendChild(extActiv);
    }
 catch (    final IOException e2) {
      e2.printStackTrace();
    }
catch (    final SAXException e) {
      e.printStackTrace();
    }
catch (    final ParserConfigurationException e) {
      e.printStackTrace();
    }
  }
  if (hasProps) {
    final Element postPhaseElement=context.getPostPhaseElement();
    appendUpdateProperties(context,nodeTemplate,nodeInstanceURLVarName,restCallResponseVarName,postPhaseElement);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Appends BPEL Code that updates InstanceData for the given NodeTemplate. Needs initialization code on the global level in the plan. This will be checked and appended if needed.
 * @param context the TemplateContext of the NodeTemplate
 * @param nodeTemplate the NodeTemplate to handle
 * @return true iff appending all BPEL code was successful
 */
public boolean handleBuild(final BPELPlanContext context,final AbstractNodeTemplate nodeTemplate){
  final boolean hasProps=checkProperties(nodeTemplate.getProperties());
  final String serviceInstanceVarName=context.getServiceInstanceURLVarName();
  if (serviceInstanceVarName == null) {
    return false;
  }
  final String serviceInstanceIDVarName=context.getServiceInstanceIDVarName();
  if (serviceInstanceIDVarName == null) {
    return false;
  }
  final String instanceDataAPIVarName=context.getServiceTemplateURLVar();
  if (instanceDataAPIVarName == null) {
    return false;
  }
  final String restCallResponseVarName=createRESTResponseVar(context);
  if (restCallResponseVarName == null) {
    return false;
  }
  final String stateVarName=createStateVar(context,context.getNodeTemplate().getId());
  if (stateVarName == null) {
    return false;
  }
  try {
    final String bpelString=this.fragments.generateBPEL4RESTLightNodeInstancePOST(instanceDataAPIVarName,serviceInstanceIDVarName,context.getNodeTemplate().getId(),restCallResponseVarName);
    Node createNodeInstanceExActiv=ModelUtils.string2dom(bpelString);
    createNodeInstanceExActiv=context.importNode(createNodeInstanceExActiv);
    context.getPrePhaseElement().appendChild(createNodeInstanceExActiv);
  }
 catch (  final IOException e2) {
    e2.printStackTrace();
  }
catch (  final SAXException e) {
    e.printStackTrace();
  }
catch (  final ParserConfigurationException e) {
    e.printStackTrace();
  }
  String nodeInstanceURLVarName="String_Node_Str";
  if (context.findInstanceURLVar(context.getNodeTemplate().getId(),true) == null) {
    nodeInstanceURLVarName=createInstanceURLVar(context,context.getNodeTemplate().getId());
  }
 else {
    nodeInstanceURLVarName=context.findInstanceURLVar(context.getNodeTemplate().getId(),true);
  }
  if (nodeInstanceURLVarName == null) {
    return false;
  }
  String nodeInstanceIDVarName="String_Node_Str";
  if (context.findInstanceIDVar(context.getNodeTemplate().getId(),true) == null) {
    nodeInstanceIDVarName=createInstanceIDVar(context,context.getNodeTemplate().getId());
  }
 else {
    nodeInstanceIDVarName=context.findInstanceIDVar(context.getNodeTemplate().getId(),true);
  }
  if (nodeInstanceIDVarName == null) {
    return false;
  }
  try {
    final String bpelString=this.fragments.generateAssignFromNodeInstancePOSTResponseToStringVar(nodeInstanceURLVarName,nodeInstanceIDVarName,restCallResponseVarName);
    Node assignNodeInstanceUrl=ModelUtils.string2dom(bpelString);
    assignNodeInstanceUrl=context.importNode(assignNodeInstanceUrl);
    context.getPrePhaseElement().appendChild(assignNodeInstanceUrl);
  }
 catch (  final IOException e2) {
    e2.printStackTrace();
  }
catch (  final SAXException e) {
    e.printStackTrace();
  }
catch (  final ParserConfigurationException e) {
    e.printStackTrace();
  }
  try {
    final BPELProcessFragments frag=new BPELProcessFragments();
    Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + System.currentTimeMillis(),"String_Node_Str",stateVarName);
    assignNode=context.importNode(assignNode);
    context.getPrePhaseElement().appendChild(assignNode);
    final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
    Node extActiv=ModelUtils.string2dom(bpelString);
    extActiv=context.importNode(extActiv);
    context.getPrePhaseElement().appendChild(extActiv);
  }
 catch (  final IOException e2) {
    e2.printStackTrace();
  }
catch (  final SAXException e) {
    e.printStackTrace();
  }
catch (  final ParserConfigurationException e) {
    e.printStackTrace();
  }
  String lastSetState="String_Node_Str";
  final Element provisioningPhaseElement=context.getProvisioningPhaseElement();
  final List<Element> assignContentElements=fetchInvokerCallAssigns(provisioningPhaseElement);
  final List<String> operationNames=new ArrayList<>();
  for (  final Element assignContentElement : assignContentElements) {
    final String operationName=fetchOperationName(assignContentElement);
    operationNames.add(operationName);
    final String preState=InstanceStates.getOperationPreState(operationName);
    final String postState=InstanceStates.getOperationPostState(operationName);
    if (preState != null) {
      try {
        final BPELProcessFragments frag=new BPELProcessFragments();
        Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + operationName + "String_Node_Str"+ System.currentTimeMillis(),"String_Node_Str" + preState + "String_Node_Str",stateVarName);
        assignNode=context.importNode(assignNode);
        lastSetState=preState;
        final Node bpelAssignNode=assignContentElement.getParentNode().getParentNode().getParentNode().getParentNode();
        bpelAssignNode.getParentNode().insertBefore(assignNode,bpelAssignNode);
        final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
        Node extActiv=ModelUtils.string2dom(bpelString);
        extActiv=context.importNode(extActiv);
        bpelAssignNode.getParentNode().insertBefore(extActiv,bpelAssignNode);
      }
 catch (      final IOException e2) {
        e2.printStackTrace();
      }
catch (      final SAXException e) {
        e.printStackTrace();
      }
catch (      final ParserConfigurationException e) {
        e.printStackTrace();
      }
    }
    if (postState != null) {
      try {
        final BPELProcessFragments frag=new BPELProcessFragments();
        Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + operationName + "String_Node_Str"+ System.currentTimeMillis(),"String_Node_Str" + postState + "String_Node_Str",stateVarName);
        assignNode=context.importNode(assignNode);
        lastSetState=postState;
        final Node bpelAssignNode=assignContentElement.getParentNode().getParentNode().getParentNode().getParentNode();
        final String reqVarName=fetchRequestVarNameFromInvokerAssign(assignContentElement);
        final Element invokerReceiveElement=fetchInvokerReceive((Element)bpelAssignNode,reqVarName);
        assignNode=invokerReceiveElement.getParentNode().insertBefore(assignNode,invokerReceiveElement.getNextSibling());
        final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
        Node extActiv=ModelUtils.string2dom(bpelString);
        extActiv=context.importNode(extActiv);
        final Element afterElement=(Element)invokerReceiveElement.getParentNode().insertBefore(extActiv,assignNode.getNextSibling());
        if (hasProps) {
          appendUpdateProperties(context,nodeTemplate,nodeInstanceURLVarName,restCallResponseVarName,afterElement.getParentNode());
        }
      }
 catch (      final IOException e2) {
        e2.printStackTrace();
      }
catch (      final SAXException e) {
        e.printStackTrace();
      }
catch (      final ParserConfigurationException e) {
        e.printStackTrace();
      }
    }
  }
  if (lastSetState.equals("String_Node_Str")) {
    try {
      String nextState=InstanceStates.getNextStableOperationState(lastSetState);
      if (operationNames.isEmpty()) {
        nextState="String_Node_Str";
      }
      final BPELProcessFragments frag=new BPELProcessFragments();
      Node assignNode=frag.createAssignXpathQueryToStringVarFragmentAsNode("String_Node_Str" + System.currentTimeMillis(),"String_Node_Str" + nextState + "String_Node_Str",stateVarName);
      assignNode=context.importNode(assignNode);
      final String bpelString=this.fragments.generateBPEL4RESTLightPUTInstanceState(nodeInstanceURLVarName,stateVarName);
      Node extActiv=ModelUtils.string2dom(bpelString);
      extActiv=context.importNode(extActiv);
      context.getPostPhaseElement().appendChild(assignNode);
      context.getPostPhaseElement().appendChild(extActiv);
    }
 catch (    final IOException e2) {
      e2.printStackTrace();
    }
catch (    final SAXException e) {
      e.printStackTrace();
    }
catch (    final ParserConfigurationException e) {
      e.printStackTrace();
    }
  }
  if (hasProps) {
    final Element postPhaseElement=context.getPostPhaseElement();
    appendUpdateProperties(context,nodeTemplate,nodeInstanceURLVarName,restCallResponseVarName,postPhaseElement);
  }
  return true;
}