Program: 185125
Project: 185125
Buggy source:
public static void diff(Node xml2,Node xml1,Writer out) throws DiffXException, IOException {
  try {
    DiffXConfig diffxConfig=new DiffXConfig();
    diffxConfig.setIgnoreWhiteSpace(false);
    diffxConfig.setPreserveWhiteSpace(true);
    log(xml1.getNodeName());
    log("String_Node_Str" + xml1.getChildNodes().getLength());
    log(xml2.getNodeName());
    log("String_Node_Str" + xml2.getChildNodes().getLength());
    if (!xml1.getNodeName().equals(xml2.getNodeName()) || ((xml1.getChildNodes().getLength() <= 3) && (xml2.getChildNodes().getLength() <= 3))) {
      log("String_Node_Str");
      Main.diff(xml1,xml2,out,diffxConfig);
      out.close();
      return;
    }
    DOMRecorder loader=new DOMRecorder();
    loader.setConfig(diffxConfig);
    log("String_Node_Str");
    List<EventSequence> leftES=new ArrayList<EventSequence>();
    for (int i=0; i < xml1.getChildNodes().getLength(); i++) {
      if (xml1.getChildNodes().item(i).getNodeType() != 3) {
        Element e=(Element)xml1.getChildNodes().item(i);
        e.setAttributeNS("String_Node_Str","String_Node_Str","String_Node_Str");
        leftES.add(loader.process(e));
      }
    }
    EventSequenceComparator leftESC=new EventSequenceComparator(leftES);
    List<EventSequence> rightES=new ArrayList<EventSequence>();
    for (int i=0; i < xml2.getChildNodes().getLength(); i++) {
      if (xml2.getChildNodes().item(i).getNodeType() != 3) {
        Element e=(Element)xml2.getChildNodes().item(i);
        e.setAttributeNS("String_Node_Str","String_Node_Str","String_Node_Str");
        rightES.add(loader.process(e));
      }
    }
    EventSequenceComparator rightESC=new EventSequenceComparator(rightES);
    log("String_Node_Str");
    RangeDifference[] rd=RangeDifferencer.findDifferences(leftESC,rightESC);
    for (int i=0; i < rd.length; i++) {
      RangeDifference rdi=rd[i];
      log(rdi.kindString() + "String_Node_Str" + rdi.leftStart()+ "String_Node_Str"+ rdi.leftLength()+ "String_Node_Str"+ rdi.rightStart()+ "String_Node_Str"+ rdi.rightLength());
    }
    log("String_Node_Str");
    SmartXMLFormatter formatter=new SmartXMLFormatter(out);
    formatter.setConfig(diffxConfig);
    String rootNodeName=xml1.getNodeName();
    out.append("String_Node_Str" + rootNodeName + "String_Node_Str"+ xml1.getPrefix()+ "String_Node_Str"+ xml1.getNamespaceURI()+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ Constants.BASE_NS+ "String_Node_Str"+ "String_Node_Str"+ Constants.DELETE_NS+ "String_Node_Str"+ "String_Node_Str"+ Constants.BASE_NS+ "String_Node_Str"+ "String_Node_Str");
    int leftIdx=0;
    for (int i=0; i < rd.length; i++) {
      RangeDifference rdi=rd[i];
      if (rdi.leftStart() > leftIdx) {
        for (int k=leftIdx; k < rdi.leftStart(); k++) {
          addComment("String_Node_Str",formatter);
          formatter.declarePrefixMapping(leftESC.getItem(k).getPrefixMapping());
          leftESC.getItem(k).format(formatter);
          addComment("String_Node_Str",formatter);
        }
        leftIdx=rdi.leftStart();
      }
      EventSequence seq1=new EventSequence();
      for (int k=rdi.leftStart(); k < rdi.leftEnd(); k++) {
        if (rdi.kind() == rdi.CHANGE) {
          seq1.addSequence(leftESC.getItem(k));
          PrefixMapping existingPM=leftESC.getItem(k).getPrefixMapping();
          seq1.getPrefixMapping().add(existingPM);
        }
 else {
          formatter.declarePrefixMapping(leftESC.getItem(k).getPrefixMapping());
          addComment("String_Node_Str",formatter);
          leftESC.getItem(k).format(formatter);
          addComment("String_Node_Str",formatter);
        }
      }
      EventSequence seq2=new EventSequence();
      for (int k=rdi.rightStart(); k < rdi.rightEnd(); k++) {
        if (rdi.kind() == rdi.CHANGE) {
          seq2.addSequence(rightESC.getItem(k));
          PrefixMapping existingPM=rightESC.getItem(k).getPrefixMapping();
          seq2.getPrefixMapping().add(existingPM);
        }
      }
      leftIdx=rdi.leftEnd();
      addComment("String_Node_Str",formatter);
      Main.diff(seq1,seq2,formatter,diffxConfig);
      addComment("String_Node_Str",formatter);
    }
    addComment("String_Node_Str",formatter);
    if (rd.length > 0) {
      for (int k=rd[rd.length - 1].leftEnd(); k < leftESC.getRangeCount(); k++) {
        leftESC.getItem(k).format(formatter);
      }
    }
    out.append("String_Node_Str" + rootNodeName + "String_Node_Str");
  }
 catch (  IndexOutOfBoundsException e) {
    e.printStackTrace();
    throw new DiffXException(e);
  }
}

Fixed version (ground truth):
public static void diff(Node xml2,Node xml1,Writer out) throws DiffXException, IOException {
  try {
    DiffXConfig diffxConfig=new DiffXConfig();
    diffxConfig.setIgnoreWhiteSpace(false);
    diffxConfig.setPreserveWhiteSpace(true);
    log(xml1.getNodeName());
    log("String_Node_Str" + xml1.getChildNodes().getLength());
    log(xml2.getNodeName());
    log("String_Node_Str" + xml2.getChildNodes().getLength());
    if (!xml1.getNodeName().equals(xml2.getNodeName()) || ((xml1.getChildNodes().getLength() <= 3) && (xml2.getChildNodes().getLength() <= 3))) {
      log("String_Node_Str");
      Main.diff(xml1,xml2,out,diffxConfig);
      out.close();
      return;
    }
    DOMRecorder loader=new DOMRecorder();
    loader.setConfig(diffxConfig);
    log("String_Node_Str");
    List<EventSequence> leftES=new ArrayList<EventSequence>();
    for (int i=0; i < xml1.getChildNodes().getLength(); i++) {
      if (xml1.getChildNodes().item(i).getNodeType() != 3) {
        Element e=(Element)xml1.getChildNodes().item(i);
        e.setAttributeNS("String_Node_Str","String_Node_Str","String_Node_Str");
        leftES.add(loader.process(e));
      }
    }
    EventSequenceComparator leftESC=new EventSequenceComparator(leftES);
    List<EventSequence> rightES=new ArrayList<EventSequence>();
    for (int i=0; i < xml2.getChildNodes().getLength(); i++) {
      if (xml2.getChildNodes().item(i).getNodeType() != 3) {
        Element e=(Element)xml2.getChildNodes().item(i);
        e.setAttributeNS("String_Node_Str","String_Node_Str","String_Node_Str");
        rightES.add(loader.process(e));
      }
    }
    EventSequenceComparator rightESC=new EventSequenceComparator(rightES);
    log("String_Node_Str");
    RangeDifference[] rd=RangeDifferencer.findDifferences(leftESC,rightESC);
    SmartXMLFormatter formatter=new SmartXMLFormatter(out);
    formatter.setConfig(diffxConfig);
    String rootNodeName=xml1.getNodeName();
    openResult(rootNodeName,out);
    if (rd.length == 0) {
      log("String_Node_Str");
      addComment("String_Node_Str",formatter);
      for (      EventSequence es : leftES) {
        es.format(formatter);
      }
      closeResult(rootNodeName,out);
      return;
    }
    for (int i=0; i < rd.length; i++) {
      RangeDifference rdi=rd[i];
      log(rdi.kindString() + "String_Node_Str" + rdi.leftStart()+ "String_Node_Str"+ rdi.leftLength()+ "String_Node_Str"+ rdi.rightStart()+ "String_Node_Str"+ rdi.rightLength());
    }
    log("String_Node_Str");
    int leftIdx=0;
    for (int i=0; i < rd.length; i++) {
      RangeDifference rdi=rd[i];
      if (rdi.leftStart() > leftIdx) {
        for (int k=leftIdx; k < rdi.leftStart(); k++) {
          addComment("String_Node_Str",formatter);
          formatter.declarePrefixMapping(leftESC.getItem(k).getPrefixMapping());
          leftESC.getItem(k).format(formatter);
          addComment("String_Node_Str",formatter);
        }
        leftIdx=rdi.leftStart();
      }
      EventSequence seq1=new EventSequence();
      for (int k=rdi.leftStart(); k < rdi.leftEnd(); k++) {
        if (rdi.kind() == rdi.CHANGE) {
          seq1.addSequence(leftESC.getItem(k));
          PrefixMapping existingPM=leftESC.getItem(k).getPrefixMapping();
          seq1.getPrefixMapping().add(existingPM);
        }
 else {
          formatter.declarePrefixMapping(leftESC.getItem(k).getPrefixMapping());
          addComment("String_Node_Str",formatter);
          leftESC.getItem(k).format(formatter);
          addComment("String_Node_Str",formatter);
        }
      }
      EventSequence seq2=new EventSequence();
      for (int k=rdi.rightStart(); k < rdi.rightEnd(); k++) {
        if (rdi.kind() == rdi.CHANGE) {
          seq2.addSequence(rightESC.getItem(k));
          PrefixMapping existingPM=rightESC.getItem(k).getPrefixMapping();
          seq2.getPrefixMapping().add(existingPM);
        }
      }
      leftIdx=rdi.leftEnd();
      addComment("String_Node_Str",formatter);
      Main.diff(seq1,seq2,formatter,diffxConfig);
      addComment("String_Node_Str",formatter);
    }
    addComment("String_Node_Str",formatter);
    if (rd.length > 0) {
      for (int k=rd[rd.length - 1].leftEnd(); k < leftESC.getRangeCount(); k++) {
        leftESC.getItem(k).format(formatter);
      }
    }
    closeResult(rootNodeName,out);
  }
 catch (  IndexOutOfBoundsException e) {
    e.printStackTrace();
    throw new DiffXException(e);
  }
}