Program: 64393
Project: 64393
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext,XPathFragment rootFragment){
  XPathFragment xmlRootFrag=null;
  if (objectValue instanceof XMLRoot) {
    XMLRoot xmlRoot=(XMLRoot)objectValue;
    xmlRootFrag=new XPathFragment();
    if (xmlRoot.getNamespaceURI() != null && !xmlRoot.getNamespaceURI().equals(namespaceResolver.getDefaultNamespaceURI())) {
      String prefix=namespaceResolver.resolveNamespaceURI(xmlRoot.getNamespaceURI());
      xmlRootFrag.setXPath(prefix + Constants.COLON + xmlRoot.getLocalName());
      xmlRootFrag.setNamespaceURI(xmlRoot.getNamespaceURI());
    }
 else {
      xmlRootFrag.setXPath(xmlRoot.getLocalName());
      if (xmlRoot.getNamespaceURI() != null && xmlRoot.getNamespaceURI().length() > 0) {
        xmlRootFrag.setNamespaceURI(xmlRoot.getNamespaceURI());
      }
    }
  }
  Marshaller marshaller=marshalRecord.getMarshaller();
  objectValue=xmlBinaryDataMapping.convertObjectValueToDataValue(objectValue,(Session)session,marshaller);
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.isAttribute()) {
    if (objectValue == null) {
      marshalRecord.closeStartGroupingElements(groupingFragment);
      return true;
    }
  }
 else {
    marshalRecord.closeStartGroupingElements(groupingFragment);
    XPathFragment elementFragment=xPathFragment;
    if (xmlRootFrag != null) {
      elementFragment=xmlRootFrag;
    }
    if (objectValue == null) {
      XPathNode holderXPathNode=new XPathNode();
      holderXPathNode.setXPathFragment(elementFragment);
      marshalRecord.addGroupingElement(holderXPathNode);
      boolean returnVal=xmlBinaryDataMapping.getNullPolicy().directMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
      if (returnVal) {
        marshalRecord.endElement(elementFragment,namespaceResolver);
      }
      marshalRecord.removeGroupingElement(holderXPathNode);
      return returnVal;
    }
 else     if (!xPathFragment.isSelfFragment) {
      marshalRecord.openStartElement(elementFragment,namespaceResolver);
      marshalRecord.closeStartElement();
    }
  }
  String c_id=null;
  byte[] bytes=null;
  String mimeType=this.xmlBinaryDataMapping.getMimeType(object);
  if (mimeType == null) {
    mimeType="String_Node_Str";
  }
  if (xmlBinaryDataMapping.isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)objectValue);
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
    }
  }
 else   if (marshalRecord.isXOPPackage() && !xmlBinaryDataMapping.shouldInlineBinaryData()) {
    XPathFragment lastFrag=((Field)xmlBinaryDataMapping.getField()).getLastXPathFragment();
    if (xmlRootFrag != null) {
      lastFrag=xmlRootFrag;
    }
    String localName=null;
    String namespaceUri=null;
    if (rootFragment != null) {
      localName=rootFragment.getLocalName();
      namespaceUri=rootFragment.getNamespaceURI();
    }
    if (!lastFrag.isSelfFragment) {
      localName=lastFrag.getLocalName();
      namespaceUri=lastFrag.getNamespaceURI();
    }
    if (objectValue.getClass() == CoreClassConstants.APBYTE) {
      bytes=(byte[])objectValue;
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,this.xmlBinaryDataMapping.getMimeType(object),localName,namespaceUri);
    }
 else     if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)objectValue,localName,namespaceUri);
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),localName,namespaceUri);
    }
  }
  if (xPathFragment.isAttribute()) {
    if (c_id != null) {
      marshalRecord.attribute(xPathFragment,namespaceResolver,c_id);
    }
 else {
      String value=getValueToWrite(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,session);
      marshalRecord.attribute(xPathFragment,namespaceResolver,value);
    }
    marshalRecord.closeStartGroupingElements(groupingFragment);
    return true;
  }
  if (xmlBinaryDataMapping.isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    if (c_id != null) {
      marshalRecord.characters(c_id);
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataMapping.shouldInlineBinaryData()) {
      if (c_id == null) {
        marshalRecord.characters(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,mimeType,false);
      }
 else {
        String xopPrefix=null;
        if (namespaceResolver != null) {
          xopPrefix=namespaceResolver.resolveNamespaceURI(Constants.XOP_URL);
        }
        boolean addDeclaration=false;
        if (xopPrefix == null || namespaceResolver == null) {
          addDeclaration=true;
          xopPrefix=Constants.XOP_PREFIX;
          namespaceResolver=new org.eclipse.persistence.oxm.NamespaceResolver();
          namespaceResolver.put(xopPrefix,Constants.XOP_URL);
        }
        XPathFragment xopInclude=new XPathFragment(xopPrefix + "String_Node_Str");
        xopInclude.setNamespaceURI(Constants.XOP_URL);
        marshalRecord.openStartElement(xopInclude,namespaceResolver);
        marshalRecord.attribute(Constants.EMPTY_STRING,"String_Node_Str","String_Node_Str",c_id);
        if (addDeclaration) {
          marshalRecord.namespaceDeclaration(xopPrefix,Constants.XOP_URL);
        }
        marshalRecord.closeStartElement();
        marshalRecord.endElement(xopInclude,namespaceResolver);
      }
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
  if (!xPathFragment.isSelfFragment()) {
    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,XPathFragment rootFragment){
  XPathFragment xmlRootFrag=null;
  if (objectValue instanceof Root) {
    Root xmlRoot=(Root)objectValue;
    xmlRootFrag=new XPathFragment();
    if (xmlRoot.getNamespaceURI() != null && !xmlRoot.getNamespaceURI().equals(namespaceResolver.getDefaultNamespaceURI())) {
      String prefix=namespaceResolver.resolveNamespaceURI(xmlRoot.getNamespaceURI());
      xmlRootFrag.setXPath(prefix + Constants.COLON + xmlRoot.getLocalName());
      xmlRootFrag.setNamespaceURI(xmlRoot.getNamespaceURI());
    }
 else {
      xmlRootFrag.setXPath(xmlRoot.getLocalName());
      if (xmlRoot.getNamespaceURI() != null && xmlRoot.getNamespaceURI().length() > 0) {
        xmlRootFrag.setNamespaceURI(xmlRoot.getNamespaceURI());
      }
    }
  }
  Marshaller marshaller=marshalRecord.getMarshaller();
  objectValue=xmlBinaryDataMapping.convertObjectValueToDataValue(objectValue,(Session)session,marshaller);
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.isAttribute()) {
    if (objectValue == null) {
      marshalRecord.closeStartGroupingElements(groupingFragment);
      return true;
    }
  }
 else {
    marshalRecord.closeStartGroupingElements(groupingFragment);
    XPathFragment elementFragment=xPathFragment;
    if (xmlRootFrag != null) {
      elementFragment=xmlRootFrag;
    }
    if (objectValue == null) {
      XPathNode holderXPathNode=new XPathNode();
      holderXPathNode.setXPathFragment(elementFragment);
      marshalRecord.addGroupingElement(holderXPathNode);
      boolean returnVal=xmlBinaryDataMapping.getNullPolicy().directMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
      if (returnVal) {
        marshalRecord.endElement(elementFragment,namespaceResolver);
      }
      marshalRecord.removeGroupingElement(holderXPathNode);
      return returnVal;
    }
 else     if (!xPathFragment.isSelfFragment) {
      marshalRecord.openStartElement(elementFragment,namespaceResolver);
      marshalRecord.closeStartElement();
    }
  }
  String c_id=null;
  byte[] bytes=null;
  String mimeType=this.xmlBinaryDataMapping.getMimeType(object);
  if (mimeType == null) {
    mimeType="String_Node_Str";
  }
  if (xmlBinaryDataMapping.isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)objectValue);
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
    }
  }
 else   if (marshalRecord.isXOPPackage() && !xmlBinaryDataMapping.shouldInlineBinaryData()) {
    XPathFragment lastFrag=((Field)xmlBinaryDataMapping.getField()).getLastXPathFragment();
    if (xmlRootFrag != null) {
      lastFrag=xmlRootFrag;
    }
    String localName=null;
    String namespaceUri=null;
    if (rootFragment != null) {
      localName=rootFragment.getLocalName();
      namespaceUri=rootFragment.getNamespaceURI();
    }
    if (!lastFrag.isSelfFragment) {
      localName=lastFrag.getLocalName();
      namespaceUri=lastFrag.getNamespaceURI();
    }
    if (objectValue.getClass() == CoreClassConstants.APBYTE) {
      bytes=(byte[])objectValue;
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,this.xmlBinaryDataMapping.getMimeType(object),localName,namespaceUri);
    }
 else     if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)objectValue,localName,namespaceUri);
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),localName,namespaceUri);
    }
  }
  if (xPathFragment.isAttribute()) {
    if (c_id != null) {
      marshalRecord.attribute(xPathFragment,namespaceResolver,c_id);
    }
 else {
      String value=getValueToWrite(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,session);
      marshalRecord.attribute(xPathFragment,namespaceResolver,value);
    }
    marshalRecord.closeStartGroupingElements(groupingFragment);
    return true;
  }
  if (xmlBinaryDataMapping.isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    if (c_id != null) {
      marshalRecord.characters(c_id);
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataMapping.shouldInlineBinaryData()) {
      if (c_id == null) {
        marshalRecord.characters(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,mimeType,false);
      }
 else {
        String xopPrefix=null;
        if (namespaceResolver != null) {
          xopPrefix=namespaceResolver.resolveNamespaceURI(Constants.XOP_URL);
        }
        boolean addDeclaration=false;
        if (xopPrefix == null || namespaceResolver == null) {
          addDeclaration=true;
          xopPrefix=Constants.XOP_PREFIX;
          namespaceResolver=new org.eclipse.persistence.oxm.NamespaceResolver();
          namespaceResolver.put(xopPrefix,Constants.XOP_URL);
        }
        XPathFragment xopInclude=new XPathFragment(xopPrefix + "String_Node_Str");
        xopInclude.setNamespaceURI(Constants.XOP_URL);
        marshalRecord.openStartElement(xopInclude,namespaceResolver);
        marshalRecord.attribute(Constants.EMPTY_STRING,"String_Node_Str","String_Node_Str",c_id);
        if (addDeclaration) {
          marshalRecord.namespaceDeclaration(xopPrefix,Constants.XOP_URL);
        }
        marshalRecord.closeStartElement();
        marshalRecord.endElement(xopInclude,namespaceResolver);
      }
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
  if (!xPathFragment.isSelfFragment()) {
    marshalRecord.endElement(xPathFragment,namespaceResolver);
  }
  return true;
}