Program: 63582
Project: 63582
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  objectValue=xmlCompositeObjectMapping.convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
  if (null == objectValue) {
    return xmlCompositeObjectMapping.getNullPolicy().compositeObjectMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.hasAttribute) {
    ObjectBuilder tob=(ObjectBuilder)xmlCompositeObjectMapping.getReferenceDescriptor().getObjectBuilder();
    MappingNodeValue textMappingNodeValue=(MappingNodeValue)tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
    Mapping textMapping=textMappingNodeValue.getMapping();
    if (textMapping.isAbstractDirectMapping()) {
      DirectMapping xmlDirectMapping=(DirectMapping)textMapping;
      Object fieldValue=xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(objectValue,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((Field)xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue,session);
      if (fieldValue != null) {
        marshalRecord.attribute(xPathFragment,namespaceResolver,fieldValue,schemaType);
      }
 else {
        XMLMarshalException ex=XMLMarshalException.nullValueNotAllowed(this.xmlCompositeObjectMapping.getAttributeName(),this.xmlCompositeObjectMapping.getDescriptor().getJavaClass().getName());
        try {
          marshalRecord.getMarshaller().getErrorHandler().warning(new SAXParseException(null,null,ex));
        }
 catch (        Exception saxException) {
          throw ex;
        }
      }
      marshalRecord.closeStartGroupingElements(groupingFragment);
      return true;
    }
 else {
      return textMappingNodeValue.marshalSingleValue(xPathFragment,marshalRecord,objectValue,textMapping.getAttributeValueFromObject(objectValue),session,namespaceResolver,marshalContext);
    }
  }
  boolean isSelfFragment=xPathFragment.isSelfFragment;
  marshalRecord.closeStartGroupingElements(groupingFragment);
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeObjectMapping.getKeepAsElementPolicy();
  if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && objectValue instanceof Node) {
    if (isSelfFragment) {
      NodeList children=((org.w3c.dom.Element)objectValue).getChildNodes();
      for (int i=0, childrenLength=children.getLength(); i < childrenLength; i++) {
        Node next=children.item(i);
        short nodeType=next.getNodeType();
        if (nodeType == Node.ELEMENT_NODE) {
          marshalRecord.node(next,marshalRecord.getNamespaceResolver());
          return true;
        }
 else         if (nodeType == Node.TEXT_NODE) {
          marshalRecord.characters(((Text)next).getNodeValue());
          return true;
        }
      }
      return false;
    }
 else {
      marshalRecord.node((Node)objectValue,marshalRecord.getNamespaceResolver());
      return true;
    }
  }
  Descriptor descriptor=(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null) {
    descriptor=(Descriptor)session.getDescriptor(objectValue.getClass());
  }
 else   if (descriptor.hasInheritance()) {
    Class objectValueClass=objectValue.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(Descriptor)session.getDescriptor(objectValueClass);
    }
  }
  if (descriptor != null) {
    marshalRecord.beforeContainmentMarshal(objectValue);
    ObjectBuilder objectBuilder=(ObjectBuilder)descriptor.getObjectBuilder();
    CoreAttributeGroup group=marshalRecord.getCurrentAttributeGroup();
    CoreAttributeItem item=group.getItem(getMapping().getAttributeName());
    CoreAttributeGroup nestedGroup=XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
    if (item != null) {
      if (item.getGroups() != null) {
        nestedGroup=item.getGroup(descriptor.getJavaClass());
      }
      if (nestedGroup == null) {
        nestedGroup=item.getGroup() == null ? XMLRecord.DEFAULT_ATTRIBUTE_GROUP : item.getGroup();
      }
    }
    marshalRecord.pushAttributeGroup(nestedGroup);
    if (!(isSelfFragment || xPathFragment.nameIsText)) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
    }
    List extraNamespaces=null;
    if (!marshalRecord.hasEqualNamespaceResolvers()) {
      extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,false);
      writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    }
    if (!isSelfFragment) {
      marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor,(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor(),(Field)xmlCompositeObjectMapping.getField(),false);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshalRecord.getMarshaller(),xPathFragment);
    marshalRecord.afterContainmentMarshal(object,objectValue);
    marshalRecord.popAttributeGroup();
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces,session);
  }
 else {
    if (Constants.UNKNOWN_OR_TRANSIENT_CLASS.equals(xmlCompositeObjectMapping.getReferenceClassName())) {
      throw XMLMarshalException.descriptorNotFoundInProject(objectValue.getClass().getName());
    }
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,null,objectValue);
    }
    QName schemaType=((Field)xmlCompositeObjectMapping.getField()).getSchemaTypeForValue(objectValue,session);
    updateNamespaces(schemaType,marshalRecord,((Field)xmlCompositeObjectMapping.getField()));
    marshalRecord.characters(schemaType,objectValue,null,false);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  boolean isNilFlag=isNil(objectValue);
  objectValue=xmlCompositeObjectMapping.convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
  if (null == objectValue) {
    return xmlCompositeObjectMapping.getNullPolicy().compositeObjectMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.hasAttribute) {
    ObjectBuilder tob=(ObjectBuilder)xmlCompositeObjectMapping.getReferenceDescriptor().getObjectBuilder();
    MappingNodeValue textMappingNodeValue=(MappingNodeValue)tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
    Mapping textMapping=textMappingNodeValue.getMapping();
    if (textMapping.isAbstractDirectMapping()) {
      DirectMapping xmlDirectMapping=(DirectMapping)textMapping;
      Object fieldValue=xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(objectValue,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((Field)xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue,session);
      if (fieldValue != null) {
        marshalRecord.attribute(xPathFragment,namespaceResolver,fieldValue,schemaType);
      }
 else {
        XMLMarshalException ex=XMLMarshalException.nullValueNotAllowed(this.xmlCompositeObjectMapping.getAttributeName(),this.xmlCompositeObjectMapping.getDescriptor().getJavaClass().getName());
        try {
          marshalRecord.getMarshaller().getErrorHandler().warning(new SAXParseException(null,null,ex));
        }
 catch (        Exception saxException) {
          throw ex;
        }
      }
      marshalRecord.closeStartGroupingElements(groupingFragment);
      return true;
    }
 else {
      return textMappingNodeValue.marshalSingleValue(xPathFragment,marshalRecord,objectValue,textMapping.getAttributeValueFromObject(objectValue),session,namespaceResolver,marshalContext);
    }
  }
  boolean isSelfFragment=xPathFragment.isSelfFragment;
  marshalRecord.closeStartGroupingElements(groupingFragment);
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeObjectMapping.getKeepAsElementPolicy();
  if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && objectValue instanceof Node) {
    if (isSelfFragment) {
      NodeList children=((org.w3c.dom.Element)objectValue).getChildNodes();
      for (int i=0, childrenLength=children.getLength(); i < childrenLength; i++) {
        Node next=children.item(i);
        short nodeType=next.getNodeType();
        if (nodeType == Node.ELEMENT_NODE) {
          marshalRecord.node(next,marshalRecord.getNamespaceResolver());
          return true;
        }
 else         if (nodeType == Node.TEXT_NODE) {
          marshalRecord.characters(((Text)next).getNodeValue());
          return true;
        }
      }
      return false;
    }
 else {
      marshalRecord.node((Node)objectValue,marshalRecord.getNamespaceResolver());
      return true;
    }
  }
  Descriptor descriptor=(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null) {
    descriptor=(Descriptor)session.getDescriptor(objectValue.getClass());
  }
 else   if (descriptor.hasInheritance()) {
    Class objectValueClass=objectValue.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(Descriptor)session.getDescriptor(objectValueClass);
    }
  }
  if (descriptor != null) {
    marshalRecord.beforeContainmentMarshal(objectValue);
    ObjectBuilder objectBuilder=(ObjectBuilder)descriptor.getObjectBuilder();
    CoreAttributeGroup group=marshalRecord.getCurrentAttributeGroup();
    CoreAttributeItem item=group.getItem(getMapping().getAttributeName());
    CoreAttributeGroup nestedGroup=XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
    if (item != null) {
      if (item.getGroups() != null) {
        nestedGroup=item.getGroup(descriptor.getJavaClass());
      }
      if (nestedGroup == null) {
        nestedGroup=item.getGroup() == null ? XMLRecord.DEFAULT_ATTRIBUTE_GROUP : item.getGroup();
      }
    }
    marshalRecord.pushAttributeGroup(nestedGroup);
    if (!(isSelfFragment || xPathFragment.nameIsText)) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
      if (isNilFlag) {
        marshalRecord.nilSimple(namespaceResolver);
      }
    }
    List extraNamespaces=null;
    if (!marshalRecord.hasEqualNamespaceResolvers()) {
      extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,false);
      writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    }
    if (!isSelfFragment) {
      marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor,(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor(),(Field)xmlCompositeObjectMapping.getField(),false);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshalRecord.getMarshaller(),xPathFragment);
    marshalRecord.afterContainmentMarshal(object,objectValue);
    marshalRecord.popAttributeGroup();
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces,session);
  }
 else {
    if (Constants.UNKNOWN_OR_TRANSIENT_CLASS.equals(xmlCompositeObjectMapping.getReferenceClassName())) {
      throw XMLMarshalException.descriptorNotFoundInProject(objectValue.getClass().getName());
    }
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,null,objectValue);
    }
    QName schemaType=((Field)xmlCompositeObjectMapping.getField()).getSchemaTypeForValue(objectValue,session);
    updateNamespaces(schemaType,marshalRecord,((Field)xmlCompositeObjectMapping.getField()));
    marshalRecord.characters(schemaType,objectValue,null,false);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  return true;
}