Program: 66541
Project: 66541
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 (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
    String c_id=XMLConstants.EMPTY_STRING;
    byte[] bytes=null;
    String elementName=field.getLastXPathFragment().getLocalName();
    String namespaceUri=field.getLastXPathFragment().getNamespaceURI();
    if (field.getLastXPathFragment().isSelfFragment()) {
      DOMRecord domRecord=(DOMRecord)record;
      if (domRecord.getDOM().getNodeType() == Node.ELEMENT_NODE) {
        elementName=domRecord.getDOM().getLocalName();
        namespaceUri=domRecord.getDOM().getNamespaceURI();
      }
    }
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      if (getAttributeClassification() == ClassConstants.ABYTE) {
        attributeValue=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).convertObject(attributeValue,ClassConstants.APBYTE);
      }
      bytes=(byte[])attributeValue;
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,this.getMimeType(parent),elementName,namespaceUri);
    }
 else     if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)attributeValue,elementName,namespaceUri);
      if (c_id == null) {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
        bytes=data.getData();
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),elementName,namespaceUri);
    }
    if (c_id == null) {
      XMLField textField=null;
      if (field.isSelfField()) {
        textField=new XMLField(XMLConstants.TEXT);
      }
 else {
        textField=new XMLField(field.getXPath() + '/' + XMLConstants.TEXT);
      }
      textField.setNamespaceResolver(field.getNamespaceResolver());
      textField.setSchemaType(field.getSchemaType());
      record.put(textField,bytes);
    }
 else {
      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=null;
      if (field.isSelfField()) {
        incxpath=prefix + "String_Node_Str";
        xpath=(prefix + include);
      }
 else {
        incxpath=xpath + '/' + prefix+ "String_Node_Str";
        xpath+=('/' + 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() + '/' + XMLConstants.TEXT);
      textField.setNamespaceResolver(field.getNamespaceResolver());
      textField.setSchemaType(field.getSchemaType());
      record.put(textField,c_id);
    }
 catch (    Exception ex) {
    }
  }
 else {
    XMLField textField=null;
    if (field.isSelfField()) {
      textField=new XMLField(XMLConstants.TEXT);
    }
 else {
      textField=new XMLField(field.getXPath() + '/' + XMLConstants.TEXT);
    }
    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);
    }
    return;
  }
  if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
    String c_id=XMLConstants.EMPTY_STRING;
    byte[] bytes=null;
    String elementName=field.getLastXPathFragment().getLocalName();
    String namespaceUri=field.getLastXPathFragment().getNamespaceURI();
    if (field.getLastXPathFragment().isSelfFragment()) {
      DOMRecord domRecord=(DOMRecord)record;
      if (domRecord.getDOM().getNodeType() == Node.ELEMENT_NODE) {
        elementName=domRecord.getDOM().getLocalName();
        namespaceUri=domRecord.getDOM().getNamespaceURI();
      }
    }
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      if (getAttributeClassification() == ClassConstants.ABYTE) {
        attributeValue=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).convertObject(attributeValue,ClassConstants.APBYTE);
      }
      bytes=(byte[])attributeValue;
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,this.getMimeType(parent),elementName,namespaceUri);
    }
 else     if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)attributeValue,elementName,namespaceUri);
      if (c_id == null) {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
        bytes=data.getData();
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue,marshaller,getMimeType(parent));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),elementName,namespaceUri);
    }
    if (c_id == null) {
      XMLField textField=null;
      if (field.isSelfField()) {
        textField=new XMLField(XMLConstants.TEXT);
      }
 else {
        textField=new XMLField(field.getXPath() + '/' + XMLConstants.TEXT);
      }
      textField.setNamespaceResolver(field.getNamespaceResolver());
      textField.setSchemaType(field.getSchemaType());
      record.put(textField,bytes);
    }
 else {
      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=null;
      if (field.isSelfField()) {
        incxpath=prefix + "String_Node_Str";
        xpath=(prefix + include);
      }
 else {
        incxpath=xpath + '/' + prefix+ "String_Node_Str";
        xpath+=('/' + 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() + '/' + XMLConstants.TEXT);
      textField.setNamespaceResolver(field.getNamespaceResolver());
      textField.setSchemaType(field.getSchemaType());
      record.put(textField,c_id);
    }
 catch (    Exception ex) {
    }
  }
 else {
    XMLField textField=null;
    if (field.isSelfField()) {
      textField=new XMLField(XMLConstants.TEXT);
    }
 else {
      textField=new XMLField(field.getXPath() + '/' + XMLConstants.TEXT);
    }
    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);
    }
  }
}