Program: 67432
Project: 67432
Buggy source:
public void writeSingleValue(Object attributeValue,Object parent,XMLRecord record,AbstractSession session){
  XMLMarshaller marshaller=record.getMarshaller();
  if (getConverter() != null) {
    Converter converter=getConverter();
    if (converter instanceof XMLConverter) {
      attributeValue=((XMLConverter)converter).convertObjectValueToDataValue(attributeValue,session,record.getMarshaller());
    }
 else {
      attributeValue=converter.convertObjectValueToDataValue(attributeValue,session);
    }
  }
  XMLField field=(XMLField)getField();
  if (field.getLastXPathFragment().isAttribute()) {
    if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
      try {
        String value=null;
        if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
          value=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)attributeValue);
        }
 else {
          XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
          byte[] bytes=data.getData();
          value=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
        }
        record.put(field,value);
      }
 catch (      ClassCastException cce) {
        throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName());
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,record.getMarshaller(),getMimeType(parent));
      String base64Value=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData());
      record.put(field,base64Value);
    }
  }
  if ((marshaller.getAttachmentMarshaller() != null) && marshaller.getAttachmentMarshaller().isXOPPackage() && !isSwaRef()&& !shouldInlineBinaryData()) {
    String c_id="String_Node_Str";
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      if (getAttributeClassification() == ClassConstants.ABYTE) {
        attributeValue=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).convertObject(attributeValue,ClassConstants.APBYTE);
      }
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((byte[])attributeValue,0,((byte[])attributeValue).length,this.getMimeType(parent),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
 else     if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)attributeValue,field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
      byte[] bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
    String xpath=this.getXPath();
    String prefix=null;
    boolean prefixAlreadyDefined=false;
    NamespaceResolver resolver=field.getNamespaceResolver();
    if (resolver != null) {
      prefix=resolver.resolveNamespaceURI(XMLConstants.XOP_URL);
    }
    if (prefix == null) {
      prefix=XMLConstants.XOP_PREFIX;
      resolver=new NamespaceResolver();
      resolver.put(prefix,XMLConstants.XOP_URL);
    }
 else {
      prefixAlreadyDefined=true;
    }
    String incxpath=xpath + "String_Node_Str" + prefix+ "String_Node_Str";
    xpath+=("String_Node_Str" + prefix + include);
    XMLField xpathField=new XMLField(xpath);
    xpathField.setNamespaceResolver(resolver);
    record.put(xpathField,c_id);
    XMLField incField=new XMLField(incxpath);
    incField.setNamespaceResolver(resolver);
    Object obj=record.getIndicatingNoEntry(incField);
    if (!prefixAlreadyDefined && 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" + prefix,XMLConstants.XOP_URL);
      }
    }
  }
 else   if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    try {
      String c_id=null;
      if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)attributeValue);
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
        byte[] bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
      }
      XMLField textField=new XMLField(field.getXPath() + "String_Node_Str");
      textField.setNamespaceResolver(field.getNamespaceResolver());
      textField.setSchemaType(field.getSchemaType());
      record.put(textField,c_id);
    }
 catch (    Exception ex) {
    }
  }
 else {
    XMLField textField=new XMLField(field.getXPath() + "String_Node_Str");
    textField.setNamespaceResolver(field.getNamespaceResolver());
    textField.setSchemaType(field.getSchemaType());
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      record.put(textField,attributeValue);
    }
 else {
      byte[] bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent)).getData();
      record.put(textField,bytes);
    }
  }
}

Fixed version (ground truth):
public void writeSingleValue(Object attributeValue,Object parent,XMLRecord record,AbstractSession session){
  XMLMarshaller marshaller=record.getMarshaller();
  if (getConverter() != null) {
    Converter converter=getConverter();
    if (converter instanceof XMLConverter) {
      attributeValue=((XMLConverter)converter).convertObjectValueToDataValue(attributeValue,session,record.getMarshaller());
    }
 else {
      attributeValue=converter.convertObjectValueToDataValue(attributeValue,session);
    }
  }
  XMLField field=(XMLField)getField();
  if (field.getLastXPathFragment().isAttribute()) {
    if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
      try {
        String value=null;
        if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
          value=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)attributeValue);
        }
 else {
          XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
          byte[] bytes=data.getData();
          value=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
        }
        record.put(field,value);
      }
 catch (      ClassCastException cce) {
        throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName());
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,record.getMarshaller(),getMimeType(parent));
      String base64Value=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData());
      record.put(field,base64Value);
    }
  }
  if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
    String c_id="String_Node_Str";
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      if (getAttributeClassification() == ClassConstants.ABYTE) {
        attributeValue=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).convertObject(attributeValue,ClassConstants.APBYTE);
      }
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((byte[])attributeValue,0,((byte[])attributeValue).length,this.getMimeType(parent),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
 else     if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)attributeValue,field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
      byte[] bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
    String xpath=this.getXPath();
    String prefix=null;
    boolean prefixAlreadyDefined=false;
    NamespaceResolver resolver=field.getNamespaceResolver();
    if (resolver != null) {
      prefix=resolver.resolveNamespaceURI(XMLConstants.XOP_URL);
    }
    if (prefix == null) {
      prefix=XMLConstants.XOP_PREFIX;
      resolver=new NamespaceResolver();
      resolver.put(prefix,XMLConstants.XOP_URL);
    }
 else {
      prefixAlreadyDefined=true;
    }
    String incxpath=xpath + "String_Node_Str" + prefix+ "String_Node_Str";
    xpath+=("String_Node_Str" + prefix + include);
    XMLField xpathField=new XMLField(xpath);
    xpathField.setNamespaceResolver(resolver);
    record.put(xpathField,c_id);
    XMLField incField=new XMLField(incxpath);
    incField.setNamespaceResolver(resolver);
    Object obj=record.getIndicatingNoEntry(incField);
    if (!prefixAlreadyDefined && 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" + prefix,XMLConstants.XOP_URL);
      }
    }
  }
 else   if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    try {
      String c_id=null;
      if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)attributeValue);
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
        byte[] bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
      }
      XMLField textField=new XMLField(field.getXPath() + "String_Node_Str");
      textField.setNamespaceResolver(field.getNamespaceResolver());
      textField.setSchemaType(field.getSchemaType());
      record.put(textField,c_id);
    }
 catch (    Exception ex) {
    }
  }
 else {
    XMLField textField=new XMLField(field.getXPath() + "String_Node_Str");
    textField.setNamespaceResolver(field.getNamespaceResolver());
    textField.setSchemaType(field.getSchemaType());
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      record.put(textField,attributeValue);
    }
 else {
      byte[] bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent)).getData();
      record.put(textField,bytes);
    }
  }
}