Program: 67430
Project: 67430
Buggy source:
public Object getValueToWrite(Object value,Object parent,XMLRecord record,XMLField field,XMLField includeField,AbstractSession session){
  XMLMarshaller marshaller=record.getMarshaller();
  Object element=value;
  boolean isAttribute=((XMLField)getField()).getLastXPathFragment().isAttribute();
  if (getValueConverter() != null) {
    Converter converter=getValueConverter();
    if (converter instanceof XMLConverter) {
      element=((XMLConverter)converter).convertObjectValueToDataValue(element,session,record.getMarshaller());
    }
 else {
      element=converter.convertObjectValueToDataValue(element,session);
    }
  }
  if (isAttribute) {
    if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
      try {
        String id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)element);
        element=id;
      }
 catch (      ClassCastException cce) {
        throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName());
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(element,record.getMarshaller(),mimeTypePolicy.getMimeType(parent));
      String base64Value=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData());
      element=base64Value;
    }
  }
 else {
    if ((marshaller.getAttachmentMarshaller() != null) && marshaller.getAttachmentMarshaller().isXOPPackage() && !isSwaRef()&& !shouldInlineBinaryData()) {
      String c_id="String_Node_Str";
      if ((getCollectionContentType() == ClassConstants.ABYTE) || (getCollectionContentType() == ClassConstants.APBYTE)) {
        if (getCollectionContentType() == ClassConstants.ABYTE) {
          element=session.getDatasourcePlatform().getConversionManager().convertObject(element,ClassConstants.APBYTE);
        }
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((byte[])element,0,((byte[])element).length,this.mimeTypePolicy.getMimeType(parent),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
      }
 else       if (getCollectionContentType() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)element,field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(element,marshaller,this.mimeTypePolicy.getMimeType(parent));
        byte[] bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
      }
      DOMRecord include=new DOMRecord(field.getLastXPathFragment().getLocalName());
      include.setSession(session);
      include.put(includeField,c_id);
      element=include;
      NamespaceResolver resolver=((XMLField)getField()).getNamespaceResolver();
      if (resolver == null || resolver.resolveNamespaceURI(XMLConstants.XOP_URL) == null) {
        resolver=new NamespaceResolver();
        resolver.put(XMLConstants.XOP_PREFIX,XMLConstants.XOP_URL);
        String xpath=XMLConstants.XOP_PREFIX + "String_Node_Str" + INCLUDE;
        XMLField incField=new XMLField(xpath);
        incField.setNamespaceResolver(resolver);
        Object obj=include.getIndicatingNoEntry(incField);
        if (obj != null && obj instanceof DOMRecord) {
          if (((DOMRecord)obj).getDOM().getNodeType() == Node.ELEMENT_NODE) {
            ((Element)((DOMRecord)obj).getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + XMLConstants.XOP_PREFIX,XMLConstants.XOP_URL);
          }
        }
      }
    }
 else     if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
      try {
        String c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)element);
        element=c_id;
      }
 catch (      Exception ex) {
      }
    }
 else {
      if (!((getCollectionContentType() == ClassConstants.ABYTE) || (getCollectionContentType() == ClassConstants.APBYTE))) {
        element=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(element,marshaller,this.mimeTypePolicy.getMimeType(parent)).getData();
      }
    }
  }
  return element;
}

Fixed version (ground truth):
public Object getValueToWrite(Object value,Object parent,XMLRecord record,XMLField field,XMLField includeField,AbstractSession session){
  XMLMarshaller marshaller=record.getMarshaller();
  Object element=value;
  boolean isAttribute=((XMLField)getField()).getLastXPathFragment().isAttribute();
  if (getValueConverter() != null) {
    Converter converter=getValueConverter();
    if (converter instanceof XMLConverter) {
      element=((XMLConverter)converter).convertObjectValueToDataValue(element,session,record.getMarshaller());
    }
 else {
      element=converter.convertObjectValueToDataValue(element,session);
    }
  }
  if (isAttribute) {
    if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
      try {
        String id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)element);
        element=id;
      }
 catch (      ClassCastException cce) {
        throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName());
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(element,record.getMarshaller(),mimeTypePolicy.getMimeType(parent));
      String base64Value=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData());
      element=base64Value;
    }
  }
 else {
    if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
      String c_id="String_Node_Str";
      if ((getCollectionContentType() == ClassConstants.ABYTE) || (getCollectionContentType() == ClassConstants.APBYTE)) {
        if (getCollectionContentType() == ClassConstants.ABYTE) {
          element=session.getDatasourcePlatform().getConversionManager().convertObject(element,ClassConstants.APBYTE);
        }
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((byte[])element,0,((byte[])element).length,this.mimeTypePolicy.getMimeType(parent),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
      }
 else       if (getCollectionContentType() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)element,field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(element,marshaller,this.mimeTypePolicy.getMimeType(parent));
        byte[] bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
      }
      DOMRecord include=new DOMRecord(field.getLastXPathFragment().getLocalName());
      include.setSession(session);
      include.put(includeField,c_id);
      element=include;
      NamespaceResolver resolver=((XMLField)getField()).getNamespaceResolver();
      if (resolver == null || resolver.resolveNamespaceURI(XMLConstants.XOP_URL) == null) {
        resolver=new NamespaceResolver();
        resolver.put(XMLConstants.XOP_PREFIX,XMLConstants.XOP_URL);
        String xpath=XMLConstants.XOP_PREFIX + "String_Node_Str" + INCLUDE;
        XMLField incField=new XMLField(xpath);
        incField.setNamespaceResolver(resolver);
        Object obj=include.getIndicatingNoEntry(incField);
        if (obj != null && obj instanceof DOMRecord) {
          if (((DOMRecord)obj).getDOM().getNodeType() == Node.ELEMENT_NODE) {
            ((Element)((DOMRecord)obj).getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + XMLConstants.XOP_PREFIX,XMLConstants.XOP_URL);
          }
        }
      }
    }
 else     if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
      try {
        String c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)element);
        element=c_id;
      }
 catch (      Exception ex) {
      }
    }
 else {
      if (!((getCollectionContentType() == ClassConstants.ABYTE) || (getCollectionContentType() == ClassConstants.APBYTE))) {
        element=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(element,marshaller,this.mimeTypePolicy.getMimeType(parent)).getData();
      }
    }
  }
  return element;
}