Program: 63576
Project: 63576
Buggy source:
@Override public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (objectValue == null) {
    AbstractNullPolicy nullPolicy=xmlBinaryDataCollectionMapping.getNullPolicy();
    if (nullPolicy.getMarshalNullRepresentation() != XMLNullRepresentationType.ABSENT_NODE) {
      XPathNode holderXPathNode=new XPathNode();
      holderXPathNode.setXPathFragment(xPathFragment);
      marshalRecord.addGroupingElement(holderXPathNode);
      boolean returnVal=xmlBinaryDataCollectionMapping.getNullPolicy().directMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
      if (returnVal) {
        marshalRecord.endElement(xPathFragment,namespaceResolver);
      }
      marshalRecord.removeGroupingElement(holderXPathNode);
      return returnVal;
    }
    return true;
  }
  String mimeType=this.xmlBinaryDataCollectionMapping.getMimeType(object);
  String attachmentType=mimeType;
  if (mimeType == null) {
    mimeType=Constants.EMPTY_STRING;
    attachmentType="String_Node_Str";
  }
  Marshaller marshaller=marshalRecord.getMarshaller();
  objectValue=xmlBinaryDataCollectionMapping.convertObjectValueToDataValue(objectValue,session,marshaller);
  marshalRecord.openStartElement(xPathFragment,namespaceResolver);
  marshalRecord.closeStartElement();
  if (xmlBinaryDataCollectionMapping.isSwaRef() && marshaller.getAttachmentMarshaller() != null) {
    String c_id=null;
    byte[] bytes=null;
    if (xmlBinaryDataCollectionMapping.getAttributeElementClass() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)objectValue);
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataCollectionMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
    }
    if (c_id != null) {
      marshalRecord.characters(c_id);
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataCollectionMapping.shouldInlineBinaryData()) {
      XPathFragment lastFrag=((Field)xmlBinaryDataCollectionMapping.getField()).getLastXPathFragment();
      String c_id=Constants.EMPTY_STRING;
      byte[] bytes=null;
      if (objectValue.getClass() == CoreClassConstants.APBYTE) {
        bytes=(byte[])objectValue;
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,attachmentType,lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
 else       if (xmlBinaryDataCollectionMapping.getAttributeElementClass() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)objectValue,lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataCollectionMapping.getMimeTypePolicy().getMimeType(object));
        bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
      if (c_id == null) {
        marshalRecord.characters(((Field)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
      }
 else {
        boolean addDeclaration=false;
        String xopPrefix=null;
        if (marshalRecord.getNamespaceResolver() != null) {
          xopPrefix=marshalRecord.getNamespaceResolver().resolveNamespaceURI(Constants.XOP_URL);
        }
        if (xopPrefix == null) {
          addDeclaration=true;
          xopPrefix=marshalRecord.getNamespaceResolver().generatePrefix(Constants.XOP_PREFIX);
          marshalRecord.getNamespaceResolver().put(xopPrefix,Constants.XOP_URL);
          namespaceResolver=marshalRecord.getNamespaceResolver();
        }
        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(xPathFragment,namespaceResolver);
        if (addDeclaration) {
          marshalRecord.getNamespaceResolver().removeNamespace(Constants.XOP_PREFIX);
        }
      }
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
  marshalRecord.endElement(xPathFragment,namespaceResolver);
  return true;
}

Fixed version (ground truth):
@Override public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  Marshaller marshaller=marshalRecord.getMarshaller();
  objectValue=xmlBinaryDataCollectionMapping.convertObjectValueToDataValue(objectValue,session,marshaller);
  if (objectValue == null) {
    AbstractNullPolicy nullPolicy=xmlBinaryDataCollectionMapping.getNullPolicy();
    if (nullPolicy.getMarshalNullRepresentation() != XMLNullRepresentationType.ABSENT_NODE) {
      XPathNode holderXPathNode=new XPathNode();
      holderXPathNode.setXPathFragment(xPathFragment);
      marshalRecord.addGroupingElement(holderXPathNode);
      boolean returnVal=xmlBinaryDataCollectionMapping.getNullPolicy().directMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
      if (returnVal) {
        marshalRecord.endElement(xPathFragment,namespaceResolver);
      }
      marshalRecord.removeGroupingElement(holderXPathNode);
      return returnVal;
    }
    return true;
  }
  String mimeType=this.xmlBinaryDataCollectionMapping.getMimeType(object);
  String attachmentType=mimeType;
  if (mimeType == null) {
    mimeType=Constants.EMPTY_STRING;
    attachmentType="String_Node_Str";
  }
  marshalRecord.openStartElement(xPathFragment,namespaceResolver);
  marshalRecord.closeStartElement();
  if (xmlBinaryDataCollectionMapping.isSwaRef() && marshaller.getAttachmentMarshaller() != null) {
    String c_id=null;
    byte[] bytes=null;
    if (xmlBinaryDataCollectionMapping.getAttributeElementClass() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)objectValue);
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataCollectionMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
    }
    if (c_id != null) {
      marshalRecord.characters(c_id);
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataCollectionMapping.shouldInlineBinaryData()) {
      XPathFragment lastFrag=((Field)xmlBinaryDataCollectionMapping.getField()).getLastXPathFragment();
      String c_id=Constants.EMPTY_STRING;
      byte[] bytes=null;
      if (objectValue.getClass() == CoreClassConstants.APBYTE) {
        bytes=(byte[])objectValue;
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,attachmentType,lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
 else       if (xmlBinaryDataCollectionMapping.getAttributeElementClass() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)objectValue,lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataCollectionMapping.getMimeTypePolicy().getMimeType(object));
        bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
      if (c_id == null) {
        marshalRecord.characters(((Field)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
      }
 else {
        boolean addDeclaration=false;
        String xopPrefix=null;
        if (marshalRecord.getNamespaceResolver() != null) {
          xopPrefix=marshalRecord.getNamespaceResolver().resolveNamespaceURI(Constants.XOP_URL);
        }
        if (xopPrefix == null) {
          addDeclaration=true;
          xopPrefix=marshalRecord.getNamespaceResolver().generatePrefix(Constants.XOP_PREFIX);
          marshalRecord.getNamespaceResolver().put(xopPrefix,Constants.XOP_URL);
          namespaceResolver=marshalRecord.getNamespaceResolver();
        }
        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(xPathFragment,namespaceResolver);
        if (addDeclaration) {
          marshalRecord.getNamespaceResolver().removeNamespace(Constants.XOP_PREFIX);
        }
      }
    }
 else {
      marshalRecord.characters(((Field)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
  marshalRecord.endElement(xPathFragment,namespaceResolver);
  return true;
}