Program: 189657
Project: 189657
Buggy source:
/** 
 * Loads definitions from an input stream containing XML
 * @param stream the path to XML resource
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
public void loadDefinitionsFromXML(InputStream stream) throws ParserConfigurationException, IOException, SAXException {
  DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
  DocumentBuilder builder=dbFactory.newDocumentBuilder();
  Document document=builder.parse(stream);
  Element root=document.getDocumentElement();
  NodeList categoryNodes=root.getElementsByTagName("String_Node_Str");
  for (int c=0; c < categoryNodes.getLength(); c++) {
    Element categoryElement=(Element)categoryNodes.item(c);
    String categoryCode=categoryElement.getAttribute("String_Node_Str");
    String masterSetUuid=categoryElement.getAttribute("String_Node_Str");
    Concept masterSetConcept=MetadataUtils.existing(Concept.class,masterSetUuid);
    masterSetConcepts.put(categoryCode,masterSetConcept.getConceptId());
    Map<String,DrugReference> categoryDrugs=new HashMap<String,DrugReference>();
    List<RegimenDefinitionGroup> categoryGroups=new ArrayList<RegimenDefinitionGroup>();
    NodeList drugNodes=categoryElement.getElementsByTagName("String_Node_Str");
    for (int d=0; d < drugNodes.getLength(); d++) {
      Element drugElement=(Element)drugNodes.item(d);
      String drugCode=drugElement.getAttribute("String_Node_Str");
      String drugConceptUuid=drugElement.hasAttribute("String_Node_Str") ? drugElement.getAttribute("String_Node_Str") : null;
      String drugDrugUuid=drugElement.hasAttribute("String_Node_Str") ? drugElement.getAttribute("String_Node_Str") : null;
      DrugReference drug=(drugDrugUuid != null) ? DrugReference.fromDrugUuid(drugDrugUuid) : DrugReference.fromConceptUuid(drugConceptUuid);
      categoryDrugs.put(drugCode,drug);
    }
    NodeList groupNodes=categoryElement.getElementsByTagName("String_Node_Str");
    for (int g=0; g < groupNodes.getLength(); g++) {
      Element groupElement=(Element)groupNodes.item(g);
      String groupCode=groupElement.getAttribute("String_Node_Str");
      String groupName=groupElement.getAttribute("String_Node_Str");
      RegimenDefinitionGroup group=new RegimenDefinitionGroup(groupCode,groupName);
      categoryGroups.add(group);
      NodeList regimenNodes=groupElement.getElementsByTagName("String_Node_Str");
      for (int r=0; r < regimenNodes.getLength(); r++) {
        Element regimenElement=(Element)regimenNodes.item(r);
        String name=regimenElement.getAttribute("String_Node_Str");
        RegimenDefinition regimenDefinition=new RegimenDefinition(name,group);
        NodeList componentNodes=regimenElement.getElementsByTagName("String_Node_Str");
        for (int p=0; p < componentNodes.getLength(); p++) {
          Element componentElement=(Element)componentNodes.item(p);
          String drugCode=componentElement.getAttribute("String_Node_Str");
          Double dose=componentElement.hasAttribute("String_Node_Str") ? Double.parseDouble(componentElement.getAttribute("String_Node_Str")) : null;
          String units=componentElement.hasAttribute("String_Node_Str") ? componentElement.getAttribute("String_Node_Str") : null;
          String frequency=componentElement.hasAttribute("String_Node_Str") ? componentElement.getAttribute("String_Node_Str") : null;
          DrugReference drug=categoryDrugs.get(drugCode);
          if (drug == null)           throw new RuntimeException("String_Node_Str" + drugCode);
          regimenDefinition.addComponent(drug,dose,units,frequency);
        }
        group.addRegimen(regimenDefinition);
      }
    }
    drugs.put(categoryCode,categoryDrugs);
    regimenGroups.put(categoryCode,categoryGroups);
  }
}

Fixed version (ground truth):
/** 
 * Loads definitions from an input stream containing XML
 * @param stream the path to XML resource
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
public void loadDefinitionsFromXML(InputStream stream) throws ParserConfigurationException, IOException, SAXException {
  DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
  DocumentBuilder builder=dbFactory.newDocumentBuilder();
  Document document=builder.parse(stream);
  Element root=document.getDocumentElement();
  NodeList categoryNodes=root.getElementsByTagName("String_Node_Str");
  for (int c=0; c < categoryNodes.getLength(); c++) {
    Element categoryElement=(Element)categoryNodes.item(c);
    String categoryCode=categoryElement.getAttribute("String_Node_Str");
    String masterSetUuid=categoryElement.getAttribute("String_Node_Str");
    Concept masterSetConcept=MetadataUtils.existing(Concept.class,masterSetUuid);
    masterSetConcepts.put(categoryCode,masterSetConcept.getConceptId());
    Map<String,DrugReference> categoryDrugs=new HashMap<String,DrugReference>();
    List<RegimenDefinitionGroup> categoryGroups=new ArrayList<RegimenDefinitionGroup>();
    NodeList drugNodes=categoryElement.getElementsByTagName("String_Node_Str");
    for (int d=0; d < drugNodes.getLength(); d++) {
      Element drugElement=(Element)drugNodes.item(d);
      String drugCode=drugElement.getAttribute("String_Node_Str");
      String drugConceptUuid=drugElement.hasAttribute("String_Node_Str") ? drugElement.getAttribute("String_Node_Str") : null;
      String drugDrugUuid=drugElement.hasAttribute("String_Node_Str") ? drugElement.getAttribute("String_Node_Str") : null;
      DrugReference drug=(drugDrugUuid != null) ? DrugReference.fromDrugUuid(drugDrugUuid) : DrugReference.fromConceptUuid(drugConceptUuid);
      if (drug != null) {
        categoryDrugs.put(drugCode,drug);
      }
    }
    NodeList groupNodes=categoryElement.getElementsByTagName("String_Node_Str");
    for (int g=0; g < groupNodes.getLength(); g++) {
      Element groupElement=(Element)groupNodes.item(g);
      String groupCode=groupElement.getAttribute("String_Node_Str");
      String groupName=groupElement.getAttribute("String_Node_Str");
      RegimenDefinitionGroup group=new RegimenDefinitionGroup(groupCode,groupName);
      categoryGroups.add(group);
      NodeList regimenNodes=groupElement.getElementsByTagName("String_Node_Str");
      for (int r=0; r < regimenNodes.getLength(); r++) {
        Element regimenElement=(Element)regimenNodes.item(r);
        String name=regimenElement.getAttribute("String_Node_Str");
        RegimenDefinition regimenDefinition=new RegimenDefinition(name,group);
        NodeList componentNodes=regimenElement.getElementsByTagName("String_Node_Str");
        for (int p=0; p < componentNodes.getLength(); p++) {
          Element componentElement=(Element)componentNodes.item(p);
          String drugCode=componentElement.getAttribute("String_Node_Str");
          Double dose=componentElement.hasAttribute("String_Node_Str") ? Double.parseDouble(componentElement.getAttribute("String_Node_Str")) : null;
          String units=componentElement.hasAttribute("String_Node_Str") ? componentElement.getAttribute("String_Node_Str") : null;
          String frequency=componentElement.hasAttribute("String_Node_Str") ? componentElement.getAttribute("String_Node_Str") : null;
          DrugReference drug=categoryDrugs.get(drugCode);
          if (drug == null)           throw new RuntimeException("String_Node_Str" + drugCode);
          regimenDefinition.addComponent(drug,dose,units,frequency);
        }
        group.addRegimen(regimenDefinition);
      }
    }
    drugs.put(categoryCode,categoryDrugs);
    regimenGroups.put(categoryCode,categoryGroups);
  }
}