Program: 68809
Project: 68809
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) 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(),lastUpdated.getNamespaceResolver());
    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);
    }
 else     if (next.containsIndex()) {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        nextElement=addIndexedElement(next,xmlField,nextElement,this,!hasMore);
      }
 else {
        Object valueToWrite=getValueToWrite(value,xmlField);
        nextElement=addIndexedElement(next,xmlField,nextElement,valueToWrite,!hasMore);
        createdElements.add(nextElement);
      }
    }
 else {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        elements=addElements(next,xmlField,nextElement,this,!hasMore,sibling,docPresPolicy);
      }
 else {
        XPathFragment nextFragment=next.getNextFragment();
        if ((nextFragment != null) && nextFragment.isAttribute() && !(value instanceof List)) {
          elements=addElements(next,xmlField,nextElement,this,hasMore,sibling,docPresPolicy);
        }
 else {
          Object valueToWrite=getValueToWrite(value,xmlField);
          elements=addElements(next,xmlField,nextElement,valueToWrite,!hasMore,sibling,docPresPolicy);
          createdElements.addAll(elements);
        }
      }
      nextElement=(Element)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,xmlField.getNamespaceResolver()));
  }
  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) 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(),lastUpdated.getNamespaceResolver());
    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);
    }
 else     if (next.containsIndex()) {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        nextElement=addIndexedElement(next,xmlField,nextElement,this,!hasMore);
      }
 else {
        Object valueToWrite=getValueToWrite(value,xmlField);
        nextElement=addIndexedElement(next,xmlField,nextElement,valueToWrite,!hasMore);
        createdElements.add(nextElement);
      }
    }
 else {
      boolean hasMore=!(next.getHasText() || (next.getNextFragment() == null));
      if (hasMore) {
        elements=addElements(next,xmlField,nextElement,this,!hasMore,sibling,docPresPolicy);
      }
 else {
        XPathFragment nextFragment=next.getNextFragment();
        if ((nextFragment != null) && nextFragment.isAttribute() && !(value instanceof List)) {
          elements=addElements(next,xmlField,nextElement,this,hasMore,sibling,docPresPolicy);
        }
 else {
          Object valueToWrite=getValueToWrite(value,xmlField);
          elements=addElements(next,xmlField,nextElement,valueToWrite,!hasMore,sibling,docPresPolicy);
          createdElements.addAll(elements);
        }
      }
      nextElement=(Element)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,xmlField.getNamespaceResolver()));
  }
  return createdElements;
}