Program: 29853
Project: 29853
Buggy source:
public void updateWebXml(ContextFacade facade,File file) throws Exception {
  Map<String,String> servlets=facade.getAddedServlets();
  Map<String,String[]> mappings=facade.getServletMappings();
  List<String> listeners=facade.getListeners();
  Map<String,String> filters=facade.getAddedFilters();
  Map<String,String> servletNameFilterMappings=facade.getServletNameFilterMappings();
  Map<String,String> urlPatternFilterMappings=facade.getUrlPatternFilterMappings();
  if (!filters.isEmpty() || !listeners.isEmpty() || !servlets.isEmpty()) {
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"String_Node_Str" + file.getAbsolutePath());
    }
    DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
    Document doc=null;
    Element webapp=null;
    if ((file != null) && (file.exists())) {
      doc=dBuilder.parse(file);
      webapp=doc.getDocumentElement();
    }
 else {
      doc=dBuilder.newDocument();
      webapp=doc.createElement("String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      doc.appendChild(webapp);
    }
    boolean entryFound=false;
    for (    Map.Entry entry : filters.entrySet()) {
      NodeList filterList=doc.getElementsByTagName("String_Node_Str");
      for (int i=0; i < filterList.getLength(); i++) {
        Node filterNode=filterList.item(i);
        if (entry.getKey().equals(filterNode.getTextContent()) && filterNode.getParentNode().getNodeName().equals("String_Node_Str")) {
          NodeList children=filterNode.getParentNode().getChildNodes();
          for (int j=0; j < children.getLength(); j++) {
            Node filterClass=children.item(j);
            if (filterClass.getNodeName().equals("String_Node_Str")) {
              filterClass.setTextContent(entry.getValue().toString());
              entryFound=true;
              break;
            }
          }
        }
      }
      if (!entryFound) {
        Element filter=doc.createElement("String_Node_Str");
        Element filterName=doc.createElement("String_Node_Str");
        filterName.setTextContent(entry.getKey().toString());
        filter.appendChild(filterName);
        Element filterClass=doc.createElement("String_Node_Str");
        filterClass.setTextContent(entry.getValue().toString());
        filter.appendChild(filterClass);
        Map<String,String> initParams=facade.getFilterRegistration(entry.getKey().toString()).getInitParameters();
        if ((initParams != null) && (!initParams.isEmpty())) {
          Element initParam=doc.createElement("String_Node_Str");
          for (          Map.Entry param : initParams.entrySet()) {
            Element paramName=doc.createElement("String_Node_Str");
            paramName.setTextContent(param.getKey().toString());
            initParam.appendChild(paramName);
            Element paramValue=doc.createElement("String_Node_Str");
            paramValue.setTextContent(param.getValue().toString());
            initParam.appendChild(paramValue);
          }
          filter.appendChild(initParam);
        }
        webapp.appendChild(filter);
      }
    }
    for (    Map.Entry mapping : servletNameFilterMappings.entrySet()) {
      Element filterMapping=doc.createElement("String_Node_Str");
      Element filterName=doc.createElement("String_Node_Str");
      filterName.setTextContent(mapping.getKey().toString());
      filterMapping.appendChild(filterName);
      Element servletName=doc.createElement("String_Node_Str");
      servletName.setTextContent(mapping.getValue().toString());
      filterMapping.appendChild(servletName);
      webapp.appendChild(filterMapping);
    }
    for (    Map.Entry mapping : urlPatternFilterMappings.entrySet()) {
      Element filterMapping=doc.createElement("String_Node_Str");
      Element filterName=doc.createElement("String_Node_Str");
      filterName.setTextContent(mapping.getKey().toString());
      filterMapping.appendChild(filterName);
      Element urlPattern=doc.createElement("String_Node_Str");
      urlPattern.setTextContent(mapping.getValue().toString());
      filterMapping.appendChild(urlPattern);
      webapp.appendChild(filterMapping);
    }
    entryFound=false;
    for (    Map.Entry entry : servlets.entrySet()) {
      NodeList servletList=doc.getElementsByTagName("String_Node_Str");
      for (int i=0; i < servletList.getLength(); i++) {
        Node servletNode=servletList.item(i);
        if (entry.getKey().equals(servletNode.getTextContent()) && servletNode.getParentNode().getNodeName().equals("String_Node_Str")) {
          NodeList children=servletNode.getParentNode().getChildNodes();
          for (int j=0; j < children.getLength(); j++) {
            Node servletClass=children.item(j);
            if (servletClass.getNodeName().equals("String_Node_Str")) {
              servletClass.setTextContent(entry.getValue().toString());
              entryFound=true;
              break;
            }
          }
        }
      }
      if (!entryFound) {
        Element servlet=doc.createElement("String_Node_Str");
        Element servletName=doc.createElement("String_Node_Str");
        servletName.setTextContent(entry.getKey().toString());
        servlet.appendChild(servletName);
        Element servletClass=doc.createElement("String_Node_Str");
        servletClass.setTextContent(entry.getValue().toString());
        servlet.appendChild(servletClass);
        Map<String,String> initParams=facade.getServletRegistration(entry.getKey().toString()).getInitParameters();
        if ((initParams != null) && (!initParams.isEmpty())) {
          Element initParam=doc.createElement("String_Node_Str");
          for (          Map.Entry param : initParams.entrySet()) {
            Element paramName=doc.createElement("String_Node_Str");
            paramName.setTextContent(param.getKey().toString());
            initParam.appendChild(paramName);
            Element paramValue=doc.createElement("String_Node_Str");
            paramValue.setTextContent(param.getValue().toString());
            initParam.appendChild(paramValue);
          }
          servlet.appendChild(initParam);
        }
        webapp.appendChild(servlet);
      }
    }
    entryFound=false;
    for (    Map.Entry mapping : mappings.entrySet()) {
      NodeList servletList=doc.getElementsByTagName("String_Node_Str");
      for (int i=0; i < servletList.getLength(); i++) {
        Node servletNode=servletList.item(i);
        if (mapping.getKey().equals(servletNode.getTextContent()) && servletNode.getParentNode().getNodeName().equals("String_Node_Str")) {
          NodeList children=servletNode.getParentNode().getChildNodes();
          for (int j=0; j < children.getLength(); j++) {
            Node urlPattern=children.item(j);
            if (urlPattern.getNodeName().equals("String_Node_Str")) {
              entryFound=true;
              break;
            }
          }
        }
      }
      if (!entryFound) {
        Element servletMapping=doc.createElement("String_Node_Str");
        for (        String pattern : mappings.get(mapping.getKey())) {
          Element servletName=doc.createElement("String_Node_Str");
          servletName.setTextContent(mapping.getKey().toString());
          servletMapping.appendChild(servletName);
          Element urlPattern=doc.createElement("String_Node_Str");
          urlPattern.setTextContent(pattern);
          servletMapping.appendChild(urlPattern);
        }
        webapp.appendChild(servletMapping);
      }
    }
    for (    String listenerStr : listeners) {
      Element listener=doc.createElement("String_Node_Str");
      Element listenerClass=doc.createElement("String_Node_Str");
      listenerClass.setTextContent(listenerStr);
      listener.appendChild(listenerClass);
      webapp.appendChild(listener);
    }
    Transformer transformer=TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT,"String_Node_Str");
    DOMSource src=new DOMSource(doc);
    StreamResult result=new StreamResult(file);
    transformer.transform(src,result);
  }
}

Fixed version (ground truth):
public void updateWebXml(ContextFacade facade,File file) throws Exception {
  Map<String,String> servlets=facade.getAddedServlets();
  Map<String,String[]> mappings=facade.getServletMappings();
  List<String> listeners=facade.getListeners();
  Map<String,String> filters=facade.getAddedFilters();
  Map<String,String> servletNameFilterMappings=facade.getServletNameFilterMappings();
  Map<String,String> urlPatternFilterMappings=facade.getUrlPatternFilterMappings();
  if (!filters.isEmpty() || !listeners.isEmpty() || !servlets.isEmpty()) {
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"String_Node_Str" + file.getAbsolutePath());
    }
    DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
    Document doc=null;
    Element webapp=null;
    if ((file != null) && (file.exists())) {
      doc=dBuilder.parse(file);
      webapp=doc.getDocumentElement();
    }
 else {
      doc=dBuilder.newDocument();
      webapp=doc.createElement("String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      webapp.setAttribute("String_Node_Str","String_Node_Str");
      doc.appendChild(webapp);
    }
    boolean entryFound=false;
    for (    Map.Entry entry : filters.entrySet()) {
      NodeList filterList=doc.getElementsByTagName("String_Node_Str");
      for (int i=0; i < filterList.getLength(); i++) {
        Node filterNode=filterList.item(i);
        if (entry.getKey().equals(filterNode.getTextContent()) && filterNode.getParentNode().getNodeName().equals("String_Node_Str")) {
          NodeList children=filterNode.getParentNode().getChildNodes();
          for (int j=0; j < children.getLength(); j++) {
            Node filterClass=children.item(j);
            if (filterClass.getNodeName().equals("String_Node_Str")) {
              filterClass.setTextContent(entry.getValue().toString());
              entryFound=true;
              break;
            }
          }
        }
      }
      if (!entryFound) {
        Element filter=doc.createElement("String_Node_Str");
        Element filterName=doc.createElement("String_Node_Str");
        filterName.setTextContent(entry.getKey().toString());
        filter.appendChild(filterName);
        Element filterClass=doc.createElement("String_Node_Str");
        filterClass.setTextContent(entry.getValue().toString());
        filter.appendChild(filterClass);
        Map<String,String> initParams=facade.getFilterRegistration(entry.getKey().toString()).getInitParameters();
        if ((initParams != null) && (!initParams.isEmpty())) {
          Element initParam=doc.createElement("String_Node_Str");
          for (          Map.Entry param : initParams.entrySet()) {
            Element paramName=doc.createElement("String_Node_Str");
            paramName.setTextContent(param.getKey().toString());
            initParam.appendChild(paramName);
            Element paramValue=doc.createElement("String_Node_Str");
            paramValue.setTextContent(param.getValue().toString());
            initParam.appendChild(paramValue);
          }
          filter.appendChild(initParam);
        }
        webapp.appendChild(filter);
      }
    }
    for (    Map.Entry mapping : servletNameFilterMappings.entrySet()) {
      Element filterMapping=doc.createElement("String_Node_Str");
      Element filterName=doc.createElement("String_Node_Str");
      filterName.setTextContent(mapping.getKey().toString());
      filterMapping.appendChild(filterName);
      Element servletName=doc.createElement("String_Node_Str");
      servletName.setTextContent(mapping.getValue().toString());
      filterMapping.appendChild(servletName);
      webapp.appendChild(filterMapping);
    }
    for (    Map.Entry mapping : urlPatternFilterMappings.entrySet()) {
      Element filterMapping=doc.createElement("String_Node_Str");
      Element filterName=doc.createElement("String_Node_Str");
      filterName.setTextContent(mapping.getKey().toString());
      filterMapping.appendChild(filterName);
      Element urlPattern=doc.createElement("String_Node_Str");
      urlPattern.setTextContent(mapping.getValue().toString());
      filterMapping.appendChild(urlPattern);
      webapp.appendChild(filterMapping);
    }
    entryFound=false;
    for (    Map.Entry entry : servlets.entrySet()) {
      NodeList servletList=doc.getElementsByTagName("String_Node_Str");
      for (int i=0; i < servletList.getLength(); i++) {
        Node servletNode=servletList.item(i);
        if (entry.getKey().equals(servletNode.getTextContent()) && servletNode.getParentNode().getNodeName().equals("String_Node_Str")) {
          NodeList children=servletNode.getParentNode().getChildNodes();
          for (int j=0; j < children.getLength(); j++) {
            Node servletClass=children.item(j);
            if (servletClass.getNodeName().equals("String_Node_Str")) {
              servletClass.setTextContent(entry.getValue().toString());
              entryFound=true;
              break;
            }
          }
        }
      }
      if (!entryFound) {
        Element servlet=doc.createElement("String_Node_Str");
        Element servletName=doc.createElement("String_Node_Str");
        servletName.setTextContent(entry.getKey().toString());
        servlet.appendChild(servletName);
        Element servletClass=doc.createElement("String_Node_Str");
        servletClass.setTextContent(entry.getValue().toString());
        servlet.appendChild(servletClass);
        Map<String,String> initParams=facade.getServletRegistration(entry.getKey().toString()).getInitParameters();
        if ((initParams != null) && (!initParams.isEmpty())) {
          Element initParam=doc.createElement("String_Node_Str");
          for (          Map.Entry param : initParams.entrySet()) {
            Element paramName=doc.createElement("String_Node_Str");
            paramName.setTextContent(param.getKey().toString());
            initParam.appendChild(paramName);
            Element paramValue=doc.createElement("String_Node_Str");
            paramValue.setTextContent(param.getValue().toString());
            initParam.appendChild(paramValue);
          }
          servlet.appendChild(initParam);
        }
        webapp.appendChild(servlet);
      }
    }
    entryFound=false;
    for (    Map.Entry mapping : mappings.entrySet()) {
      NodeList servletList=doc.getElementsByTagName("String_Node_Str");
      for (int i=0; i < servletList.getLength(); i++) {
        Node servletNode=servletList.item(i);
        if (mapping.getKey().equals(servletNode.getTextContent()) && servletNode.getParentNode().getNodeName().equals("String_Node_Str")) {
          NodeList children=servletNode.getParentNode().getChildNodes();
          for (int j=0; j < children.getLength(); j++) {
            Node urlPattern=children.item(j);
            if (urlPattern.getNodeName().equals("String_Node_Str")) {
              entryFound=true;
              break;
            }
          }
        }
      }
      if (!entryFound) {
        Element servletMapping=doc.createElement("String_Node_Str");
        for (        String pattern : mappings.get(mapping.getKey())) {
          Element servletName=doc.createElement("String_Node_Str");
          servletName.setTextContent(mapping.getKey().toString());
          servletMapping.appendChild(servletName);
          Element urlPattern=doc.createElement("String_Node_Str");
          urlPattern.setTextContent(pattern);
          servletMapping.appendChild(urlPattern);
        }
        webapp.appendChild(servletMapping);
      }
    }
    for (    String listenerStr : listeners) {
      Element listener=doc.createElement("String_Node_Str");
      Element listenerClass=doc.createElement("String_Node_Str");
      listenerClass.setTextContent(listenerStr);
      listener.appendChild(listenerClass);
      webapp.appendChild(listener);
    }
    Transformer transformer=TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT,"String_Node_Str");
    if (file != null) {
      DOMSource src=new DOMSource(doc);
      StreamResult result=new StreamResult(file);
      transformer.transform(src,result);
    }
  }
}