Program: 73695
Project: 73695
Buggy source:
/** 
 * Populate the referenced child models list and update the model XML by  replacing the referenced models with place holder.  
 * @param model Model with references to be resolved.
 * @return The updates model containing the list of child models and updated content.
 * @throws XMLDBModelParsingException If thrown while parsing the XML. 
 */
public XMLDBModel populateChildModelsList(XMLDBModel model) throws XMLDBModelParsingException {
  if (model.getModel() == null) {
    return model;
  }
  model.setReferencedChildren(new ArrayList<String>());
  Document modelDocument=(Document)Utilities.parseXML(model.getModel());
  Node topEntityNode=modelDocument.getElementsByTagName("String_Node_Str").item(0);
  NodeList entityList=topEntityNode.getChildNodes();
  boolean isChanged=false;
  if (entityList != null) {
    for (int i=0; i < entityList.getLength(); i++) {
      Node entity=entityList.item(i);
      if (!"String_Node_Str".equals(entity.getNodeName())) {
        continue;
      }
      NodeList parameterList=entity.getChildNodes();
      String referencedModelId=null;
      boolean isReferenced=false;
      int noOfParametersFound=0;
      for (int j=0; j < parameterList.getLength(); j++) {
        Node parameter=parameterList.item(j);
        if ("String_Node_Str".equals(parameter.getNodeName())) {
          String name=Utilities.getValueForAttribute(parameter,"String_Node_Str");
          if (XMLDBModel.DB_MODEL_ID_ATTR.equals(name)) {
            referencedModelId=Utilities.getValueForAttribute(parameter,"String_Node_Str");
            noOfParametersFound++;
          }
 else           if (XMLDBModel.DB_REFERENCE_ATTR.equals(name)) {
            String value=Utilities.getValueForAttribute(parameter,"String_Node_Str");
            isReferenced="String_Node_Str".equals(value);
            noOfParametersFound++;
          }
          if (noOfParametersFound == 2) {
            break;
          }
        }
      }
      if (isReferenced && referencedModelId != null) {
        Element entityElement=(Element)entity.cloneNode(false);
        NodeList childNodesList=entity.getChildNodes();
        for (int k=0; k < childNodesList.getLength(); k++) {
          Node childNode=childNodesList.item(k);
          if ("String_Node_Str".equals(childNode.getNodeName())) {
            String name=Utilities.getValueForAttribute(childNode,"String_Node_Str");
            if (name != null && (name.startsWith("String_Node_Str") || XMLDBModel.DB_REFERENCE_ATTR.equals(name) || XMLDBModel.DB_MODEL_ID_ATTR.equals(name))) {
              entityElement.appendChild(childNode);
            }
          }
        }
        entityElement.setAttribute(XMLDBModel.DB_MODEL_ID_ATTR,referencedModelId);
        topEntityNode.replaceChild(entityElement,entity);
        model.addReferencedChild(referencedModelId);
        isChanged=true;
      }
    }
  }
  if (isChanged) {
    String newModelContent=Utilities.getDocumentXMLString(modelDocument);
    model.setModel(newModelContent);
  }
  return model;
}

Fixed version (ground truth):
/** 
 * Populate the referenced child models list and update the model XML by  replacing the referenced models with place holder.  
 * @param model Model with references to be resolved.
 * @return The updates model containing the list of child models and updated content.
 * @throws XMLDBModelParsingException If thrown while parsing the XML. 
 */
public XMLDBModel populateChildModelsList(XMLDBModel model) throws XMLDBModelParsingException {
  if (model.getModel() == null) {
    return model;
  }
  model.setReferencedChildren(new ArrayList<String>());
  Document modelDocument=(Document)Utilities.parseXML(model.getModel());
  Node topEntityNode=modelDocument.getElementsByTagName("String_Node_Str").item(0);
  NodeList entityList=topEntityNode.getChildNodes();
  boolean isChanged=false;
  if (entityList != null) {
    for (int i=0; i < entityList.getLength(); i++) {
      Node entity=entityList.item(i);
      if (!"String_Node_Str".equals(entity.getNodeName())) {
        continue;
      }
      NodeList parameterList=entity.getChildNodes();
      String referencedModelId=null;
      boolean isReferenced=false;
      boolean isReferencedFound=false;
      boolean dbModelIdFound=false;
      for (int j=0; j < parameterList.getLength(); j++) {
        Node parameter=parameterList.item(j);
        if ("String_Node_Str".equals(parameter.getNodeName())) {
          String name=Utilities.getValueForAttribute(parameter,"String_Node_Str");
          if (XMLDBModel.DB_MODEL_ID_ATTR.equals(name) && !dbModelIdFound) {
            referencedModelId=Utilities.getValueForAttribute(parameter,"String_Node_Str");
            dbModelIdFound=true;
          }
 else           if (XMLDBModel.DB_REFERENCE_ATTR.equals(name) && !isReferencedFound) {
            String value=Utilities.getValueForAttribute(parameter,"String_Node_Str");
            isReferenced="String_Node_Str".equals(value);
            isReferencedFound=true;
          }
          if (isReferencedFound && dbModelIdFound) {
            break;
          }
        }
      }
      if (isReferenced && referencedModelId != null) {
        Element entityElement=(Element)entity.cloneNode(false);
        NodeList childNodesList=entity.getChildNodes();
        for (int k=0; k < childNodesList.getLength(); k++) {
          Node childNode=childNodesList.item(k);
          if ("String_Node_Str".equals(childNode.getNodeName())) {
            String name=Utilities.getValueForAttribute(childNode,"String_Node_Str");
            if (name != null && (name.startsWith("String_Node_Str") || XMLDBModel.DB_REFERENCE_ATTR.equals(name) || XMLDBModel.DB_MODEL_ID_ATTR.equals(name))) {
              entityElement.appendChild(childNode);
            }
          }
        }
        entityElement.setAttribute(XMLDBModel.DB_MODEL_ID_ATTR,referencedModelId);
        topEntityNode.replaceChild(entityElement,entity);
        model.addReferencedChild(referencedModelId);
        isChanged=true;
      }
    }
  }
  if (isChanged) {
    String newModelContent=Utilities.getDocumentXMLString(modelDocument);
    model.setModel(newModelContent);
  }
  return model;
}