Program: 65442
Project: 65442
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (objectValue == null) {
    return false;
  }
  String mimeType=this.xmlBinaryDataCollectionMapping.getMimeType(object);
  if (mimeType == null) {
    mimeType=XMLConstants.EMPTY_STRING;
  }
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  if (xmlBinaryDataCollectionMapping.getValueConverter() != null) {
    Converter converter=xmlBinaryDataCollectionMapping.getValueConverter();
    if (converter instanceof XMLConverter) {
      objectValue=((XMLConverter)converter).convertObjectValueToDataValue(objectValue,session,marshaller);
    }
 else {
      objectValue=converter.convertObjectValueToDataValue(objectValue,session);
    }
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  marshalRecord.closeStartGroupingElements(groupingFragment);
  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(((XMLField)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataCollectionMapping.shouldInlineBinaryData()) {
      XPathFragment lastFrag=((XMLField)xmlBinaryDataCollectionMapping.getField()).getLastXPathFragment();
      String c_id=XMLConstants.EMPTY_STRING;
      byte[] bytes=null;
      if (objectValue.getClass() == ClassConstants.APBYTE) {
        bytes=(byte[])objectValue;
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,this.xmlBinaryDataCollectionMapping.getMimeType(object),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(((XMLField)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
      }
 else {
        boolean addDeclaration=false;
        String xopPrefix=null;
        if (marshalRecord.getNamespaceResolver() != null) {
          xopPrefix=marshalRecord.getNamespaceResolver().resolveNamespaceURI(XMLConstants.XOP_URL);
        }
        if (xopPrefix == null) {
          addDeclaration=true;
          xopPrefix=marshalRecord.getNamespaceResolver().generatePrefix(XMLConstants.XOP_PREFIX);
          marshalRecord.getNamespaceResolver().put(xopPrefix,XMLConstants.XOP_URL);
          namespaceResolver=marshalRecord.getNamespaceResolver();
        }
        XPathFragment xopInclude=new XPathFragment(xopPrefix + "String_Node_Str");
        xopInclude.setNamespaceURI(XMLConstants.XOP_URL);
        marshalRecord.openStartElement(xopInclude,namespaceResolver);
        marshalRecord.attribute(XMLConstants.EMPTY_STRING,"String_Node_Str","String_Node_Str",c_id);
        if (addDeclaration) {
          marshalRecord.attribute(XMLConstants.XMLNS_URL,xopPrefix,XMLConstants.XMLNS + XMLConstants.COLON + xopPrefix,XMLConstants.XOP_URL);
        }
        marshalRecord.closeStartElement();
        marshalRecord.endElement(xPathFragment,namespaceResolver);
        if (addDeclaration) {
          marshalRecord.getNamespaceResolver().removeNamespace(XMLConstants.XOP_PREFIX);
        }
      }
    }
 else {
      marshalRecord.characters(((XMLField)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
  marshalRecord.endElement(xPathFragment,namespaceResolver);
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (objectValue == null) {
    return false;
  }
  String mimeType=this.xmlBinaryDataCollectionMapping.getMimeType(object);
  if (mimeType == null) {
    mimeType=XMLConstants.EMPTY_STRING;
  }
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  if (xmlBinaryDataCollectionMapping.getValueConverter() != null) {
    Converter converter=xmlBinaryDataCollectionMapping.getValueConverter();
    if (converter instanceof XMLConverter) {
      objectValue=((XMLConverter)converter).convertObjectValueToDataValue(objectValue,session,marshaller);
    }
 else {
      objectValue=converter.convertObjectValueToDataValue(objectValue,session);
    }
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  marshalRecord.closeStartGroupingElements(groupingFragment);
  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(((XMLField)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataCollectionMapping.shouldInlineBinaryData()) {
      XPathFragment lastFrag=((XMLField)xmlBinaryDataCollectionMapping.getField()).getLastXPathFragment();
      String c_id=XMLConstants.EMPTY_STRING;
      byte[] bytes=null;
      if (objectValue.getClass() == ClassConstants.APBYTE) {
        bytes=(byte[])objectValue;
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,this.xmlBinaryDataCollectionMapping.getMimeType(object),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(((XMLField)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
      }
 else {
        boolean addDeclaration=false;
        String xopPrefix=null;
        if (marshalRecord.getNamespaceResolver() != null) {
          xopPrefix=marshalRecord.getNamespaceResolver().resolveNamespaceURI(XMLConstants.XOP_URL);
        }
        if (xopPrefix == null) {
          addDeclaration=true;
          xopPrefix=marshalRecord.getNamespaceResolver().generatePrefix(XMLConstants.XOP_PREFIX);
          marshalRecord.getNamespaceResolver().put(xopPrefix,XMLConstants.XOP_URL);
          namespaceResolver=marshalRecord.getNamespaceResolver();
        }
        XPathFragment xopInclude=new XPathFragment(xopPrefix + "String_Node_Str");
        xopInclude.setNamespaceURI(XMLConstants.XOP_URL);
        marshalRecord.openStartElement(xopInclude,namespaceResolver);
        marshalRecord.attribute(XMLConstants.EMPTY_STRING,"String_Node_Str","String_Node_Str",c_id);
        if (addDeclaration) {
          marshalRecord.namespaceDeclaration(xopPrefix,XMLConstants.XOP_URL);
        }
        marshalRecord.closeStartElement();
        marshalRecord.endElement(xPathFragment,namespaceResolver);
        if (addDeclaration) {
          marshalRecord.getNamespaceResolver().removeNamespace(XMLConstants.XOP_PREFIX);
        }
      }
    }
 else {
      marshalRecord.characters(((XMLField)xmlBinaryDataCollectionMapping.getField()).getSchemaType(),objectValue,mimeType,false);
    }
  }
  marshalRecord.endElement(xPathFragment,namespaceResolver);
  return true;
}