Program: 66931
Project: 66931
Buggy source:
/** 
 * Create the node path specified by <code>xpathString</code> under <code>element</code> and initialize the leaf node with <code>value</code>. This method also supports creating attributes and integer-indexed elements using the appropriate XPath syntax ('<code>@</code>' and '<code>[ ]</code>' respectively).
 * @param xmlField XMLField containing xpath expression representing the node path to create
 * @param element Root element under which to create path
 * @param value Initial value for the leaf node (this can be a value or a collection of values)
 * @return The last <code>XMLNode</code> in the path
 * @exception org.eclipse.persistence.oxm.exceptions.XMLMarshalException Thrown if passed an invalid XPath string
 */
private NodeList createCollection(XMLField xmlField,Node element,Object value,XMLField lastUpdated,DocumentPreservationPolicy docPresPolicy,AbstractSession session) throws XMLMarshalException {
  XMLNodeList createdElements=new XMLNodeList();
  if ((value == null) || (value instanceof Collection && (((Collection)value).size() == 0))) {
    return createdElements;
  }
  Node nextElement=element;
  Element sibling=null;
  if ((lastUpdated != null) && !lastUpdated.getXPathFragment().isAttribute() && !lastUpdated.getXPathFragment().nameIsText()) {
    NodeList nodes=unmarshalXPathEngine.selectElementNodes(element,lastUpdated.getXPathFragment(),getNamespaceResolverForField(lastUpdated));
    if (nodes.getLength() > 0) {
      sibling=(Element)nodes.item(nodes.getLength() - 1);
    }
  }
  NodeList elements;
  XPathFragment next=xmlField.getXPathFragment();
  while (next != null) {
    if (next.isAttribute()) {
      addAttribute(next,xmlField,nextElement,value,session);
    }
 else     if (next.containsIndex()) {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        nextElement=addIndexedElement(next,xmlField,nextElement,this,!hasMore,session);
      }
 else {
        Object valueToWrite=getValueToWrite(value,xmlField,session);
        nextElement=addIndexedElement(next,xmlField,nextElement,valueToWrite,!hasMore,session);
        createdElements.add(nextElement);
      }
    }
 else {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        elements=addElements(next,xmlField,nextElement,this,!hasMore,sibling,docPresPolicy,session);
      }
 else {
        XPathFragment nextFragment=next.getNextFragment();
        if ((nextFragment != null) && nextFragment.isAttribute() && !(value instanceof List)) {
          elements=addElements(next,xmlField,nextElement,this,hasMore,sibling,docPresPolicy,session);
        }
 else {
          Object valueToWrite=getValueToWrite(value,xmlField,session);
          elements=addElements(next,xmlField,nextElement,valueToWrite,!hasMore,sibling,docPresPolicy,session);
          createdElements.addAll(elements);
        }
      }
      nextElement=elements.item(elements.getLength() - 1);
    }
    next=next.getNextFragment();
    sibling=null;
    if ((next != null) && next.nameIsText()) {
      next=null;
    }
  }
  if (xmlField.isTypedTextField()) {
    addTypeAttributes(createdElements,xmlField,value,resolveNamespacePrefixForURI(XMLConstants.SCHEMA_INSTANCE_URL,getNamespaceResolverForField(xmlField)));
  }
  return createdElements;
}

Fixed version (ground truth):
/** 
 * Create the node path specified by <code>xpathString</code> under <code>element</code> and initialize the leaf node with <code>value</code>. This method also supports creating attributes and integer-indexed elements using the appropriate XPath syntax ('<code>@</code>' and '<code>[ ]</code>' respectively).
 * @param xmlField XMLField containing xpath expression representing the node path to create
 * @param element Root element under which to create path
 * @param value Initial value for the leaf node (this can be a value or a collection of values)
 * @return The last <code>XMLNode</code> in the path
 * @exception org.eclipse.persistence.oxm.exceptions.XMLMarshalException Thrown if passed an invalid XPath string
 */
private NodeList createCollection(XMLField xmlField,Node element,Object value,XMLField lastUpdated,DocumentPreservationPolicy docPresPolicy,AbstractSession session) throws XMLMarshalException {
  XMLNodeList createdElements=new XMLNodeList();
  if ((value == null) || (value instanceof Collection && (((Collection)value).size() == 0))) {
    return createdElements;
  }
  Node nextElement=element;
  Element sibling=null;
  XPathFragment siblingFragment=null;
  if (lastUpdated != null) {
    siblingFragment=lastUpdated.getXPathFragment();
  }
  if ((lastUpdated != null) && !siblingFragment.isAttribute() && !siblingFragment.nameIsText()) {
    NodeList nodes=unmarshalXPathEngine.selectElementNodes(element,siblingFragment,getNamespaceResolverForField(lastUpdated));
    if (nodes.getLength() > 0) {
      sibling=(Element)nodes.item(nodes.getLength() - 1);
    }
  }
  NodeList elements;
  XPathFragment next=xmlField.getXPathFragment();
  while (next != null) {
    if (next.isAttribute()) {
      addAttribute(next,xmlField,nextElement,value,session);
    }
 else     if (next.containsIndex()) {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        nextElement=addIndexedElement(next,xmlField,nextElement,this,!hasMore,session);
      }
 else {
        Object valueToWrite=getValueToWrite(value,xmlField,session);
        nextElement=addIndexedElement(next,xmlField,nextElement,valueToWrite,!hasMore,session);
        createdElements.add(nextElement);
      }
    }
 else {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        elements=addElements(next,xmlField,nextElement,this,!hasMore,sibling,docPresPolicy,session);
      }
 else {
        XPathFragment nextFragment=next.getNextFragment();
        if ((nextFragment != null) && nextFragment.isAttribute() && !(value instanceof List)) {
          elements=addElements(next,xmlField,nextElement,this,hasMore,sibling,docPresPolicy,session);
        }
 else {
          Object valueToWrite=getValueToWrite(value,xmlField,session);
          elements=addElements(next,xmlField,nextElement,valueToWrite,!hasMore,sibling,docPresPolicy,session);
          createdElements.addAll(elements);
        }
      }
      nextElement=elements.item(elements.getLength() - 1);
    }
    if (siblingFragment != null && sibling != null && siblingFragment.equals(next)) {
      siblingFragment=siblingFragment.getNextFragment();
      if ((siblingFragment != null) && !siblingFragment.isAttribute() && !siblingFragment.nameIsText()) {
        NodeList nodes=unmarshalXPathEngine.selectElementNodes(nextElement,siblingFragment,getNamespaceResolverForField(lastUpdated));
        if (nodes.getLength() > 0) {
          sibling=(Element)nodes.item(nodes.getLength() - 1);
        }
 else {
          sibling=null;
        }
      }
 else {
        sibling=null;
      }
    }
 else {
      sibling=null;
    }
    next=next.getNextFragment();
    if ((next != null) && next.nameIsText()) {
      next=null;
    }
  }
  if (xmlField.isTypedTextField()) {
    addTypeAttributes(createdElements,xmlField,value,resolveNamespacePrefixForURI(XMLConstants.SCHEMA_INSTANCE_URL,getNamespaceResolverForField(xmlField)));
  }
  return createdElements;
}