Program: 100871
Project: 100871
Buggy source:
private void moveMeta(Entry entry,Node root){
  String metaPath=(String)moveTable.get(entry.getKey());
  if (metaPath == null) {
    return;
  }
  StringTokenizer token=new StringTokenizer(metaPath,Constants.SLASH);
  Node parent=null;
  Node child=root;
  Node current=null;
  Node item=null;
  NodeList childElements;
  boolean createChild=false;
  while (token.hasMoreElements()) {
    parent=child;
    String next=(String)token.nextElement();
    Integer nextIndex=(Integer)compareTable.get(next);
    Integer currentIndex=null;
    childElements=parent.getChildNodes();
    for (int i=0; i < childElements.getLength(); i++) {
      String name=null;
      current=childElements.item(i);
      if (current.getNodeType() == Node.ELEMENT_NODE) {
        name=current.getNodeName();
      }
      if (name != null && current.getNodeName().equals(next)) {
        child=current;
        break;
      }
 else       if (name != null) {
        currentIndex=(Integer)compareTable.get(name);
        if (currentIndex.compareTo(nextIndex) > 0) {
          break;
        }
      }
    }
    if (child == parent) {
      child=parent.getOwnerDocument().createElement(next);
      ((Element)child).setAttribute(Constants.ATTRIBUTE_NAME_CLASS,"String_Node_Str" + next + "String_Node_Str");
      if (current == null || currentIndex == null || nextIndex.compareTo(currentIndex) >= 0) {
        parent.appendChild(child);
        current=null;
      }
 else {
        parent.insertBefore(child,current);
        current=null;
      }
      createChild=true;
    }
  }
  NodeList list=((Node)entry.getValue()).getChildNodes();
  for (int i=0; i < list.getLength(); i++) {
    item=list.item(i);
    if ((i == 0 && createChild) || uniqueSet.contains(entry.getKey())) {
      item=parent.getOwnerDocument().importNode(item,true);
      parent.replaceChild(item,child);
      child=item;
    }
 else {
      item=parent.getOwnerDocument().importNode(item,true);
      ((Element)parent).insertBefore(item,child);
    }
  }
}

Fixed version (ground truth):
private void moveMeta(Entry entry,Node root){
  String metaPath=(String)moveTable.get(entry.getKey());
  if (metaPath == null) {
    return;
  }
  StringTokenizer token=new StringTokenizer(metaPath,Constants.SLASH);
  Node parent=null;
  Node child=root;
  Node current=null;
  Node item=null;
  NodeList childElements;
  boolean createChild=false;
  while (token.hasMoreElements()) {
    parent=child;
    String next=(String)token.nextElement();
    Integer nextIndex=(Integer)compareTable.get(next);
    Integer currentIndex=null;
    childElements=parent.getChildNodes();
    for (int i=0; i < childElements.getLength(); i++) {
      String name=null;
      current=childElements.item(i);
      if (current.getNodeType() == Node.ELEMENT_NODE) {
        name=current.getNodeName();
      }
      if (name != null && current.getNodeName().equals(next)) {
        child=current;
        break;
      }
 else       if (name != null) {
        currentIndex=(Integer)compareTable.get(name);
        if (currentIndex == null) {
          String classValue=((Element)current).getAttribute(Constants.ATTRIBUTE_NAME_CLASS);
          String generalizedName=classValue.substring(classValue.indexOf(Constants.SLASH) + 1);
          generalizedName=generalizedName.substring(0,generalizedName.indexOf(Constants.STRING_BLANK));
          currentIndex=(Integer)compareTable.get(generalizedName);
        }
        if (currentIndex.compareTo(nextIndex) > 0) {
          break;
        }
      }
    }
    if (child == parent) {
      child=parent.getOwnerDocument().createElement(next);
      ((Element)child).setAttribute(Constants.ATTRIBUTE_NAME_CLASS,"String_Node_Str" + next + "String_Node_Str");
      if (current == null || currentIndex == null || nextIndex.compareTo(currentIndex) >= 0) {
        parent.appendChild(child);
        current=null;
      }
 else {
        parent.insertBefore(child,current);
        current=null;
      }
      createChild=true;
    }
  }
  NodeList list=((Node)entry.getValue()).getChildNodes();
  for (int i=0; i < list.getLength(); i++) {
    item=list.item(i);
    if ((i == 0 && createChild) || uniqueSet.contains(entry.getKey())) {
      item=parent.getOwnerDocument().importNode(item,true);
      parent.replaceChild(item,child);
      child=item;
    }
 else {
      item=parent.getOwnerDocument().importNode(item,true);
      ((Element)parent).insertBefore(item,child);
    }
  }
}