Program: 65907
Project: 65907
Buggy source:
/** 
 * Add a new <code>element</code> to the <code>parent</code> element.  If an element with this name already exists, return it (unless <code>forceCreate</code> is <code>true</code>).
 * @param fragment Name of element to create
 * @param namespace namespace of element to create
 * @param parent Parent element
 * @param schemaType schemaType of element to create
 * @param value Value for the new node
 * @param forceCreate If true, create a new element even if one with the same name currently exists
 * @return The <code>NodeList</code> that was created/found
 */
private NodeList addElements(XPathFragment fragment,XMLField xmlField,Node parent,Object value,boolean forceCreate,Element sibling,DocumentPreservationPolicy docPresPolicy,AbstractSession session){
  if (!forceCreate) {
    NodeList nodes=unmarshalXPathEngine.selectElementNodes(parent,fragment,getNamespaceResolverForField(xmlField));
    if (nodes.getLength() > 0) {
      return nodes;
    }
  }
  XMLNodeList elementsToReturn=new XMLNodeList();
  if (value == this) {
    String namespace=resolveNamespacePrefix(fragment,getNamespaceResolverForField(xmlField));
    Element newElement=parent.getOwnerDocument().createElementNS(namespace,fragment.getShortName());
    elementsToReturn.add(newElement);
    docPresPolicy.getNodeOrderingPolicy().appendNode(parent,newElement,sibling);
  }
 else   if (value == null) {
    elementsToReturn.add(parent);
  }
 else {
    if (value instanceof List) {
      List values=(List)value;
      for (int index=0; index < values.size(); index++) {
        Element newElement=null;
        if (values.get(index) != XMLRecord.NIL) {
          newElement=(Element)createElement(parent,fragment,xmlField,values.get(index),session);
        }
 else {
          newElement=(Element)createElement(parent,fragment,xmlField,XMLConstants.EMPTY_STRING,session);
          newElement.setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_INSTANCE_PREFIX + "String_Node_Str" + XMLConstants.SCHEMA_NIL_ATTRIBUTE,XMLConstants.BOOLEAN_STRING_TRUE);
        }
        docPresPolicy.getNodeOrderingPolicy().appendNode(parent,newElement,sibling);
        elementsToReturn.add(newElement);
        sibling=newElement;
      }
    }
 else {
      Element newElement=(Element)createElement(parent,fragment,xmlField,value,session);
      docPresPolicy.getNodeOrderingPolicy().appendNode(parent,newElement,sibling);
      elementsToReturn.add(newElement);
    }
  }
  return elementsToReturn;
}

Fixed version (ground truth):
/** 
 * Add a new <code>element</code> to the <code>parent</code> element.  If an element with this name already exists, return it (unless <code>forceCreate</code> is <code>true</code>).
 * @param fragment Name of element to create
 * @param namespace namespace of element to create
 * @param parent Parent element
 * @param schemaType schemaType of element to create
 * @param value Value for the new node
 * @param forceCreate If true, create a new element even if one with the same name currently exists
 * @return The <code>NodeList</code> that was created/found
 */
private NodeList addElements(XPathFragment fragment,XMLField xmlField,Node parent,Object value,boolean forceCreate,Element sibling,DocumentPreservationPolicy docPresPolicy,AbstractSession session){
  if (!forceCreate) {
    NodeList nodes=unmarshalXPathEngine.selectElementNodes(parent,fragment,getNamespaceResolverForField(xmlField));
    if (nodes.getLength() > 0) {
      return nodes;
    }
  }
  XMLNodeList elementsToReturn=new XMLNodeList();
  if (value == this) {
    String namespace=resolveNamespacePrefix(fragment,getNamespaceResolverForField(xmlField));
    Element newElement=parent.getOwnerDocument().createElementNS(namespace,fragment.getShortName());
    elementsToReturn.add(newElement);
    docPresPolicy.getNodeOrderingPolicy().appendNode(parent,newElement,sibling);
  }
 else   if (value == null) {
    elementsToReturn.add(parent);
  }
 else {
    if (value instanceof List) {
      List values=(List)value;
      for (int index=0; index < values.size(); index++) {
        Element newElement=null;
        if (values.get(index) != XMLRecord.NIL) {
          newElement=(Element)createElement(parent,fragment,xmlField,values.get(index),session);
        }
 else {
          newElement=(Element)createElement(parent,fragment,xmlField,XMLConstants.EMPTY_STRING,session);
          newElement.setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_INSTANCE_PREFIX + "String_Node_Str" + XMLConstants.SCHEMA_NIL_ATTRIBUTE,XMLConstants.BOOLEAN_STRING_TRUE);
        }
        docPresPolicy.getNodeOrderingPolicy().appendNode(parent,newElement,sibling);
        elementsToReturn.add(newElement);
        sibling=newElement;
      }
    }
 else {
      Element newElement=null;
      if (value != XMLRecord.NIL) {
        newElement=(Element)createElement(parent,fragment,xmlField,value,session);
      }
 else {
        newElement=(Element)createElement(parent,fragment,xmlField,XMLConstants.EMPTY_STRING,session);
        newElement.setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_INSTANCE_PREFIX + "String_Node_Str" + XMLConstants.SCHEMA_NIL_ATTRIBUTE,XMLConstants.BOOLEAN_STRING_TRUE);
      }
      docPresPolicy.getNodeOrderingPolicy().appendNode(parent,newElement,sibling);
      elementsToReturn.add(newElement);
    }
  }
  return elementsToReturn;
}