Program: 145206
Project: 145206
Buggy source:
public static void populateNode(TreeElement node,TreeElement incoming,TreeReference ref,FormDef f){
  if (node.isLeaf()) {
    IAnswerData value=incoming.getValue();
    if (value == null) {
      node.setValue(null);
    }
 else     if (node.dataType == Constants.DATATYPE_TEXT || node.dataType == Constants.DATATYPE_NULL) {
      node.setValue(value);
    }
 else {
      String textVal=(String)value.getValue();
      IAnswerData typedVal=RestoreUtils.xfFact.parseData(textVal,node.dataType,ref,f);
      node.setValue(typedVal);
    }
  }
 else {
    Vector names=new Vector();
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      if (!names.contains(child.getName())) {
        names.addElement(child.getName());
      }
    }
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      if (child.repeatable && child.getMult() != TreeReference.INDEX_TEMPLATE) {
        node.removeChildAt(i);
        i--;
      }
    }
    if (node.getNumChildren() != names.size()) {
      throw new RuntimeException("String_Node_Str");
    }
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      String expectedName=(String)names.elementAt(i);
      if (!child.getName().equals(expectedName)) {
        TreeElement child2=null;
        int j;
        for (j=i + 1; j < node.getNumChildren(); j++) {
          child2=(TreeElement)node.getChildren().elementAt(j);
          if (child2.getName().equals(expectedName)) {
            break;
          }
        }
        if (j == node.getNumChildren()) {
          throw new RuntimeException("String_Node_Str");
        }
        node.removeChildAt(j);
        node.getChildren().insertElementAt(child2,i);
      }
    }
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      Vector newChildren=incoming.getChildrenWithName(child.getName());
      TreeReference childRef=ref.clone();
      childRef.add(child.getName(),TreeReference.INDEX_UNBOUND);
      if (child.repeatable) {
        for (int k=0; k < newChildren.size(); k++) {
          TreeElement newChild=child.deepCopy(true);
          newChild.setMult(k);
          node.getChildren().insertElementAt(newChild,i + k);
          populateNode(newChild,(TreeElement)newChildren.elementAt(k),childRef,f);
          i+=k + 1;
        }
      }
 else {
        if (newChildren.size() == 0) {
          child.setRelevant(false);
        }
 else {
          populateNode(child,(TreeElement)newChildren.elementAt(0),childRef,f);
        }
      }
    }
  }
}

Fixed version (ground truth):
public static void populateNode(TreeElement node,TreeElement incoming,TreeReference ref,FormDef f){
  if (node.isLeaf()) {
    IAnswerData value=incoming.getValue();
    if (value == null) {
      node.setValue(null);
    }
 else     if (node.dataType == Constants.DATATYPE_TEXT || node.dataType == Constants.DATATYPE_NULL) {
      node.setValue(value);
    }
 else {
      String textVal=(String)value.getValue();
      IAnswerData typedVal=RestoreUtils.xfFact.parseData(textVal,node.dataType,ref,f);
      node.setValue(typedVal);
    }
  }
 else {
    Vector names=new Vector();
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      if (!names.contains(child.getName())) {
        names.addElement(child.getName());
      }
    }
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      if (child.repeatable && child.getMult() != TreeReference.INDEX_TEMPLATE) {
        node.removeChildAt(i);
        i--;
      }
    }
    if (node.getNumChildren() != names.size()) {
      throw new RuntimeException("String_Node_Str");
    }
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      String expectedName=(String)names.elementAt(i);
      if (!child.getName().equals(expectedName)) {
        TreeElement child2=null;
        int j;
        for (j=i + 1; j < node.getNumChildren(); j++) {
          child2=(TreeElement)node.getChildren().elementAt(j);
          if (child2.getName().equals(expectedName)) {
            break;
          }
        }
        if (j == node.getNumChildren()) {
          throw new RuntimeException("String_Node_Str");
        }
        node.removeChildAt(j);
        node.getChildren().insertElementAt(child2,i);
      }
    }
    for (int i=0; i < node.getNumChildren(); i++) {
      TreeElement child=(TreeElement)node.getChildren().elementAt(i);
      Vector newChildren=incoming.getChildrenWithName(child.getName());
      TreeReference childRef=ref.clone();
      childRef.add(child.getName(),TreeReference.INDEX_UNBOUND);
      if (child.repeatable) {
        for (int k=0; k < newChildren.size(); k++) {
          TreeElement newChild=child.deepCopy(true);
          newChild.setMult(k);
          node.getChildren().insertElementAt(newChild,k);
          populateNode(newChild,(TreeElement)newChildren.elementAt(k),childRef,f);
          i++;
        }
      }
 else {
        if (newChildren.size() == 0) {
          child.setRelevant(false);
        }
 else {
          populateNode(child,(TreeElement)newChildren.elementAt(0),childRef,f);
        }
      }
    }
  }
}