Program: 67214
Project: 67214
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="String_Node_Str";
    byte[] bytes=null;
    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),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());
      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(),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
    if (c_id == null) {
      XMLField textField=new XMLField(field.getXPath() + "String_Node_Str");
      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=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";
    byte[] bytes=null;
    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),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());
      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(),field.getLastXPathFragment().getLocalName(),field.getLastXPathFragment().getNamespaceURI());
    }
    if (c_id == null) {
      XMLField textField=null;
      if (field.isSelfField()) {
        textField=new XMLField("String_Node_Str");
      }
 else {
        textField=new XMLField(field.getXPath() + "String_Node_Str");
      }
      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 + "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=null;
    if (field.isSelfField()) {
      textField=new XMLField("String_Node_Str");
    }
 else {
      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);
    }
  }
}