Program: 145749
Project: 145749
Buggy source:
private static Document repair(Document document,File webAppRoot){
  Map userData=new TreeMap();
  Map snipData=new TreeMap();
  Map unknown=new TreeMap();
  Element rootEl=document.getRootElement();
  Iterator elementIt=rootEl.elementIterator();
  System.err.println("String_Node_Str");
  long identDup=0;
  long oldDup=0;
  long newDup=0;
  while (elementIt.hasNext()) {
    Element element=(Element)elementIt.next();
    Element idElement=null;
    Map data=null;
    if ("String_Node_Str".equals(element.getName())) {
      idElement=element.element("String_Node_Str");
      data=userData;
    }
 else     if ("String_Node_Str".equals(element.getName())) {
      idElement=element.element("String_Node_Str");
      data=snipData;
    }
    if (null != data && null != idElement) {
      String id=element.getName() + "String_Node_Str" + idElement.getText()+ "String_Node_Str";
      long mtime=Long.parseLong(element.element("String_Node_Str").getTextTrim());
      Element existingElement=(Element)data.get(id);
      if (existingElement != null) {
        long lastmtime=Long.parseLong(existingElement.element("String_Node_Str").getTextTrim());
        if (mtime > lastmtime) {
          newDup++;
          System.err.println("String_Node_Str" + id + "String_Node_Str"+ (mtime - lastmtime)+ "String_Node_Str");
          data.put(id,element);
        }
 else         if (mtime == lastmtime) {
          identDup++;
          System.err.println("String_Node_Str" + id);
        }
 else {
          oldDup++;
          System.err.println("String_Node_Str" + id);
        }
        if (snipData == data) {
          String name=idElement.getText();
          if (name.startsWith("String_Node_Str")) {
            String commentSnip=name.substring("String_Node_Str".length(),name.lastIndexOf("String_Node_Str"));
            Element commentEl=element.element("String_Node_Str");
            if (commentEl == null) {
              commentEl=element.addElement("String_Node_Str");
            }
            if (!commentSnip.equals(commentEl.getText())) {
              commentEl.addText(commentSnip);
              System.err.println("String_Node_Str" + name + "String_Node_Str"+ commentSnip+ "String_Node_Str");
            }
          }
 else           if (name.matches("String_Node_Str")) {
            Element parentEl=element.element("String_Node_Str");
            if (null == parentEl) {
              parentEl=element.addElement("String_Node_Str");
            }
            if (!"String_Node_Str".equals(parentEl.getText())) {
              parentEl.addText("String_Node_Str");
              System.err.println("String_Node_Str" + name + "String_Node_Str");
            }
          }
        }
      }
 else {
        data.put(id,element);
      }
    }
 else {
      System.err.println("String_Node_Str" + element.getName() + "String_Node_Str");
      unknown.put(element,element);
    }
  }
  System.err.println("String_Node_Str" + identDup + "String_Node_Str"+ newDup+ "String_Node_Str"+ oldDup+ "String_Node_Str");
  if (unknown.size() > 0) {
    System.err.println("String_Node_Str" + unknown.size() + "String_Node_Str");
  }
  Document outputDocument=DocumentHelper.createDocument();
  outputDocument.addElement(rootEl.getName());
  rootEl=outputDocument.getRootElement();
  System.err.println("String_Node_Str" + userData.size() + "String_Node_Str");
  Iterator userIt=userData.values().iterator();
  while (userIt.hasNext()) {
    Element userEl=(Element)userIt.next();
    rootEl.add(userEl.detach());
  }
  int attCount=0;
  System.err.print("String_Node_Str" + snipData.size() + "String_Node_Str");
  if (webAppRoot != null) {
    System.out.println("String_Node_Str");
  }
 else {
    System.out.println();
  }
  Iterator snipIt=snipData.values().iterator();
  while (snipIt.hasNext()) {
    Element snipEl=(Element)snipIt.next();
    if (webAppRoot != null) {
      attCount+=storeAttachments(snipEl,new File(webAppRoot,"String_Node_Str"));
      attCount+=storeOldImages(snipEl,new File(webAppRoot,"String_Node_Str"));
    }
    rootEl.add(snipEl.detach());
  }
  System.err.println("String_Node_Str" + attCount + "String_Node_Str");
  return outputDocument;
}

Fixed version (ground truth):
private static Document repair(Document document,File webAppRoot){
  Map userData=new TreeMap();
  Map snipData=new TreeMap();
  Map unknown=new TreeMap();
  Element rootEl=document.getRootElement();
  Iterator elementIt=rootEl.elementIterator();
  System.err.println("String_Node_Str");
  long identDup=0;
  long oldDup=0;
  long newDup=0;
  while (elementIt.hasNext()) {
    Element element=(Element)elementIt.next();
    Element idElement=null;
    Map data=null;
    if ("String_Node_Str".equals(element.getName())) {
      idElement=element.element("String_Node_Str");
      data=userData;
    }
 else     if ("String_Node_Str".equals(element.getName())) {
      idElement=element.element("String_Node_Str");
      data=snipData;
    }
    if (null != data && null != idElement) {
      String id=element.getName() + "String_Node_Str" + idElement.getText().toUpperCase()+ "String_Node_Str";
      long mtime=Long.parseLong(element.element("String_Node_Str").getTextTrim());
      Element existingElement=(Element)data.get(id);
      if (existingElement != null) {
        long lastmtime=Long.parseLong(existingElement.element("String_Node_Str").getTextTrim());
        if (mtime > lastmtime) {
          newDup++;
          System.err.println("String_Node_Str" + id + "String_Node_Str"+ (mtime - lastmtime)+ "String_Node_Str");
          data.put(id,element);
        }
 else         if (mtime == lastmtime) {
          identDup++;
          System.err.println("String_Node_Str" + id);
        }
 else {
          oldDup++;
          System.err.println("String_Node_Str" + id);
        }
        if (snipData == data) {
          String name=idElement.getText();
          if (name.startsWith("String_Node_Str")) {
            String commentSnip=name.substring("String_Node_Str".length(),name.lastIndexOf("String_Node_Str"));
            Element commentEl=element.element("String_Node_Str");
            if (commentEl == null) {
              commentEl=element.addElement("String_Node_Str");
            }
            if (!commentSnip.equals(commentEl.getText())) {
              commentEl.addText(commentSnip);
              System.err.println("String_Node_Str" + name + "String_Node_Str"+ commentSnip+ "String_Node_Str");
            }
          }
 else           if (name.matches("String_Node_Str")) {
            Element parentEl=element.element("String_Node_Str");
            if (null == parentEl) {
              parentEl=element.addElement("String_Node_Str");
            }
            if (!"String_Node_Str".equals(parentEl.getText())) {
              parentEl.addText("String_Node_Str");
              System.err.println("String_Node_Str" + name + "String_Node_Str");
            }
          }
        }
      }
 else {
        data.put(id,element);
      }
    }
 else {
      System.err.println("String_Node_Str" + element.getName() + "String_Node_Str");
      unknown.put(element,element);
    }
  }
  System.err.println("String_Node_Str" + identDup + "String_Node_Str"+ newDup+ "String_Node_Str"+ oldDup+ "String_Node_Str");
  if (unknown.size() > 0) {
    System.err.println("String_Node_Str" + unknown.size() + "String_Node_Str");
  }
  Document outputDocument=DocumentHelper.createDocument();
  outputDocument.addElement(rootEl.getName());
  rootEl=outputDocument.getRootElement();
  System.err.println("String_Node_Str" + userData.size() + "String_Node_Str");
  Iterator userIt=userData.values().iterator();
  while (userIt.hasNext()) {
    Element userEl=(Element)userIt.next();
    rootEl.add(userEl.detach());
  }
  int attCount=0;
  System.err.print("String_Node_Str" + snipData.size() + "String_Node_Str");
  if (webAppRoot != null) {
    System.out.println("String_Node_Str");
  }
 else {
    System.out.println();
  }
  Iterator snipIt=snipData.values().iterator();
  while (snipIt.hasNext()) {
    Element snipEl=(Element)snipIt.next();
    if (webAppRoot != null) {
      attCount+=storeAttachments(snipEl,new File(webAppRoot,"String_Node_Str"));
      attCount+=storeOldImages(snipEl,new File(webAppRoot,"String_Node_Str"));
    }
    rootEl.add(snipEl.detach());
  }
  System.err.println("String_Node_Str" + attCount + "String_Node_Str");
  return outputDocument;
}