Program: 65703
Project: 65703
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object value,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  Converter converter=xmlChoiceCollectionMapping.getConverter();
  if (null != converter) {
    if (converter instanceof XMLConverter) {
      value=((XMLConverter)converter).convertObjectValueToDataValue(value,session,marshalRecord.getMarshaller());
    }
 else {
      value=converter.convertObjectValueToDataValue(value,session);
    }
  }
  NodeValue associatedNodeValue=null;
  XMLField associatedField=null;
  Object fieldValue=value;
  if (value instanceof XMLRoot) {
    XMLRoot rootValue=(XMLRoot)value;
    String localName=rootValue.getLocalName();
    String namespaceUri=rootValue.getNamespaceURI();
    fieldValue=rootValue.getObject();
    associatedField=getFieldForName(localName,namespaceUri);
    if (associatedField == null) {
      associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(fieldValue.getClass());
    }
  }
 else {
    associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(value.getClass());
  }
  if (associatedField == null) {
    List<XMLField> sourceFields=xmlChoiceCollectionMapping.getClassToSourceFieldsMappings().get(value.getClass());
    if (sourceFields != null) {
      associatedField=sourceFields.get(0);
    }
  }
  if (associatedField != null) {
    associatedNodeValue=this.fieldToNodeValues.get(associatedField);
  }
  if (associatedNodeValue != null) {
    XPathFragment frag=associatedField.getXPathFragment();
    associatedNodeValue=((XMLChoiceCollectionMappingUnmarshalNodeValue)associatedNodeValue).getChoiceElementMarshalNodeValue();
    while (frag != null) {
      if (associatedNodeValue.isOwningNode(frag)) {
        ContainerValue nestedNodeValue=(ContainerValue)associatedNodeValue;
        nestedNodeValue.marshalSingleValue(frag,marshalRecord,object,fieldValue,session,namespaceResolver,marshalContext);
        break;
      }
      frag=frag.getNextFragment();
      if (frag == null) {
        ContainerValue nestedNodeValue=(ContainerValue)associatedNodeValue;
        nestedNodeValue.marshalSingleValue(frag,marshalRecord,object,fieldValue,session,namespaceResolver,marshalContext);
      }
    }
  }
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object value,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  Converter converter=xmlChoiceCollectionMapping.getConverter();
  if (null != converter) {
    if (converter instanceof XMLConverter) {
      value=((XMLConverter)converter).convertObjectValueToDataValue(value,session,marshalRecord.getMarshaller());
    }
 else {
      value=converter.convertObjectValueToDataValue(value,session);
    }
  }
  NodeValue associatedNodeValue=null;
  XMLField associatedField=null;
  Object fieldValue=value;
  if (value instanceof XMLRoot) {
    XMLRoot rootValue=(XMLRoot)value;
    String localName=rootValue.getLocalName();
    String namespaceUri=rootValue.getNamespaceURI();
    fieldValue=rootValue.getObject();
    associatedField=getFieldForName(localName,namespaceUri);
    if (associatedField == null) {
      associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(fieldValue.getClass());
    }
  }
 else {
    if (value.getClass() == ClassConstants.STRING && this.xmlChoiceCollectionMapping.isMixedContent()) {
      marshalMixedContent(marshalRecord,(String)value);
      return true;
    }
 else {
      associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(value.getClass());
    }
  }
  if (associatedField == null) {
    List<XMLField> sourceFields=xmlChoiceCollectionMapping.getClassToSourceFieldsMappings().get(value.getClass());
    if (sourceFields != null) {
      associatedField=sourceFields.get(0);
    }
  }
  if (associatedField != null) {
    associatedNodeValue=this.fieldToNodeValues.get(associatedField);
  }
  if (associatedNodeValue != null) {
    XPathFragment frag=associatedField.getXPathFragment();
    NodeValue unwrappedNodeValue=((XMLChoiceCollectionMappingUnmarshalNodeValue)associatedNodeValue).getChoiceElementMarshalNodeValue();
    while (frag != null) {
      if (associatedNodeValue.isOwningNode(frag)) {
        ContainerValue nestedNodeValue=(ContainerValue)unwrappedNodeValue;
        nestedNodeValue.marshalSingleValue(frag,marshalRecord,object,fieldValue,session,namespaceResolver,marshalContext);
        break;
      }
      frag=frag.getNextFragment();
      if (frag == null) {
        ContainerValue nestedNodeValue=(ContainerValue)associatedNodeValue;
        nestedNodeValue.marshalSingleValue(frag,marshalRecord,object,fieldValue,session,namespaceResolver,marshalContext);
      }
    }
  }
  return true;
}