Program: 64432
Project: 64432
Buggy source:
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,CoreAbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlAnyCollectionMapping.isReadOnly()) {
    return false;
  }
  CoreContainerPolicy 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().isApplicationJSON()) {
    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);
      nextValue=xmlAnyCollectionMapping.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);
      objectValue=xmlAnyCollectionMapping.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,CoreAbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlAnyCollectionMapping.isReadOnly()) {
    return false;
  }
  CoreContainerPolicy 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().isApplicationJSON()) {
    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);
      nextValue=xmlAnyCollectionMapping.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) {
        int valueSize=listValue.size();
        if (valueSize > 1 || !marshalRecord.getMarshaller().isReduceWildcardArrays()) {
          marshalRecord.startCollection();
        }
        for (int j=0; j < valueSize; j++) {
          marshalSingleValue(nextFragment,marshalRecord,object,listValue.get(j),session,namespaceResolver,ObjectMarshalContext.getInstance());
        }
        if (valueSize > 1 || !marshalRecord.getMarshaller().isReduceWildcardArrays()) {
          marshalRecord.endCollection();
        }
      }
    }
    return true;
  }
 else {
    Object objectValue;
    marshalRecord.startCollection();
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      objectValue=xmlAnyCollectionMapping.convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
    marshalRecord.endCollection();
    return true;
  }
}