Program: 65128
Project: 65128
Buggy source:
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,AbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlAnyCollectionMapping.isReadOnly()) {
    return false;
  }
  ContainerPolicy cp=xmlAnyCollectionMapping.getContainerPolicy();
  Object collection=xmlAnyCollectionMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (null == collection) {
    AbstractNullPolicy wrapperNP=xmlAnyCollectionMapping.getWrapperNullPolicy();
    if (wrapperNP != null && wrapperNP.getMarshalNullRepresentation().equals(XMLNullRepresentationType.XSI_NIL)) {
      marshalRecord.nilSimple(namespaceResolver);
      return true;
    }
 else {
      return false;
    }
  }
  Object iterator=cp.iteratorFor(collection);
  if (null != iterator && cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    if (xmlAnyCollectionMapping.getWrapperNullPolicy() != null) {
      XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
      marshalRecord.closeStartGroupingElements(groupingFragment);
    }
 else {
      return false;
    }
  }
  if (marshalRecord.getMarshaller().getMediaType() == MediaType.APPLICATION_JSON) {
    List<XPathFragment> frags=new ArrayList();
    List<List> values=new ArrayList<List>();
    List mixedValues=new ArrayList();
    XPathFragment xmlRootFragment;
    while (cp.hasNext(iterator)) {
      Object nextValue=cp.next(iterator,session);
      if (xmlAnyCollectionMapping.getConverter() != null) {
        nextValue=xmlAnyCollectionMapping.getConverter().convertObjectValueToDataValue(nextValue,session,marshalRecord.getMarshaller());
      }
      XPathFragment frag=getXPathFragmentForValue(nextValue,marshalRecord,marshalRecord.getMarshaller());
      if (frag != null) {
        if (frag == SIMPLE_FRAGMENT) {
          mixedValues.add(nextValue);
        }
 else {
          int index=frags.indexOf(frag);
          if (index > -1) {
            values.get(index).add(nextValue);
          }
 else {
            frags.add(frag);
            List valuesList=new ArrayList();
            valuesList.add(nextValue);
            values.add(valuesList);
          }
        }
      }
    }
    if (mixedValues.size() > 0) {
      frags.add(SIMPLE_FRAGMENT);
      values.add(mixedValues);
    }
    for (int i=0; i < frags.size(); i++) {
      XPathFragment nextFragment=frags.get(i);
      List listValue=values.get(i);
      if (nextFragment != null) {
        marshalRecord.startCollection();
        for (int j=0; j < listValue.size(); j++) {
          marshalSingleValue(nextFragment,marshalRecord,object,listValue.get(j),session,namespaceResolver,ObjectMarshalContext.getInstance());
        }
        marshalRecord.endCollection();
      }
    }
    return true;
  }
 else {
    Object objectValue;
    marshalRecord.startCollection();
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      if (xmlAnyCollectionMapping.getConverter() != null) {
        objectValue=xmlAnyCollectionMapping.getConverter().convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
      }
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
    marshalRecord.endCollection();
    return true;
  }
}

Fixed version (ground truth):
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,AbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlAnyCollectionMapping.isReadOnly()) {
    return false;
  }
  ContainerPolicy cp=xmlAnyCollectionMapping.getContainerPolicy();
  Object collection=xmlAnyCollectionMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (null == collection) {
    AbstractNullPolicy wrapperNP=xmlAnyCollectionMapping.getWrapperNullPolicy();
    if (wrapperNP != null && wrapperNP.getMarshalNullRepresentation().equals(XMLNullRepresentationType.XSI_NIL)) {
      marshalRecord.nilSimple(namespaceResolver);
      return true;
    }
 else {
      return false;
    }
  }
  Object iterator=cp.iteratorFor(collection);
  if (null != iterator && cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    return marshalRecord.emptyCollection(xPathFragment,namespaceResolver,xmlAnyCollectionMapping.getWrapperNullPolicy() != null);
  }
  if (marshalRecord.getMarshaller().getMediaType() == MediaType.APPLICATION_JSON) {
    List<XPathFragment> frags=new ArrayList();
    List<List> values=new ArrayList<List>();
    List mixedValues=new ArrayList();
    XPathFragment xmlRootFragment;
    while (cp.hasNext(iterator)) {
      Object nextValue=cp.next(iterator,session);
      if (xmlAnyCollectionMapping.getConverter() != null) {
        nextValue=xmlAnyCollectionMapping.getConverter().convertObjectValueToDataValue(nextValue,session,marshalRecord.getMarshaller());
      }
      XPathFragment frag=getXPathFragmentForValue(nextValue,marshalRecord,marshalRecord.getMarshaller());
      if (frag != null) {
        if (frag == SIMPLE_FRAGMENT) {
          mixedValues.add(nextValue);
        }
 else {
          int index=frags.indexOf(frag);
          if (index > -1) {
            values.get(index).add(nextValue);
          }
 else {
            frags.add(frag);
            List valuesList=new ArrayList();
            valuesList.add(nextValue);
            values.add(valuesList);
          }
        }
      }
    }
    if (mixedValues.size() > 0) {
      frags.add(SIMPLE_FRAGMENT);
      values.add(mixedValues);
    }
    for (int i=0; i < frags.size(); i++) {
      XPathFragment nextFragment=frags.get(i);
      List listValue=values.get(i);
      if (nextFragment != null) {
        marshalRecord.startCollection();
        for (int j=0; j < listValue.size(); j++) {
          marshalSingleValue(nextFragment,marshalRecord,object,listValue.get(j),session,namespaceResolver,ObjectMarshalContext.getInstance());
        }
        marshalRecord.endCollection();
      }
    }
    return true;
  }
 else {
    Object objectValue;
    marshalRecord.startCollection();
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      if (xmlAnyCollectionMapping.getConverter() != null) {
        objectValue=xmlAnyCollectionMapping.getConverter().convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
      }
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
    marshalRecord.endCollection();
    return true;
  }
}