Program: 67023
Project: 67023
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  if (xmlBinaryDataMapping.getConverter() != null) {
    Converter converter=xmlBinaryDataMapping.getConverter();
    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);
  if (objectValue == null) {
    return true;
  }
  if (!xPathFragment.isSelfFragment) {
    marshalRecord.openStartElement(xPathFragment,namespaceResolver);
    marshalRecord.closeStartElement();
  }
  if (xmlBinaryDataMapping.isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    String c_id=null;
    byte[] bytes=null;
    if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)objectValue);
      if (c_id == null) {
        bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object)).getData();
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
    }
    if (c_id != null) {
      marshalRecord.characters(c_id);
    }
 else {
      String value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),bytes,session);
      marshalRecord.characters(value);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataMapping.shouldInlineBinaryData()) {
      XPathFragment lastFrag=((XMLField)xmlBinaryDataMapping.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.xmlBinaryDataMapping.getMimeType(object),lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
 else       if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)objectValue,lastFrag.getLocalName(),lastFrag.getNamespaceURI());
        if (c_id == null) {
          bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object)).getData();
        }
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
        bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
      if (c_id == null) {
        String value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),bytes,session);
        marshalRecord.characters(value);
      }
 else {
        String xopPrefix=null;
        if (namespaceResolver != null) {
          xopPrefix=namespaceResolver.resolveNamespaceURI(XMLConstants.XOP_URL);
        }
        boolean addDeclaration=false;
        if (xopPrefix == null || namespaceResolver == null) {
          addDeclaration=true;
          xopPrefix=XMLConstants.XOP_PREFIX;
          namespaceResolver=new NamespaceResolver();
          namespaceResolver.put(xopPrefix,XMLConstants.XOP_URL);
        }
        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);
      }
    }
 else {
      String value=XMLConstants.EMPTY_STRING;
      if ((objectValue.getClass() == ClassConstants.ABYTE) || (objectValue.getClass() == ClassConstants.APBYTE)) {
        value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,session);
      }
 else {
        byte[] bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object)).getData();
        value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),bytes,session);
      }
      marshalRecord.characters(value);
    }
  }
  if (!xPathFragment.isSelfFragment()) {
    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){
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  if (xmlBinaryDataMapping.getConverter() != null) {
    Converter converter=xmlBinaryDataMapping.getConverter();
    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);
  if (objectValue == null) {
    return true;
  }
  if (!xPathFragment.isSelfFragment) {
    marshalRecord.openStartElement(xPathFragment,namespaceResolver);
    marshalRecord.closeStartElement();
  }
  if (xmlBinaryDataMapping.isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    String c_id=null;
    byte[] bytes=null;
    if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler)objectValue);
      if (c_id == null) {
        bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object)).getData();
      }
    }
 else {
      XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
      bytes=data.getData();
      c_id=marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes,0,bytes.length);
    }
    if (c_id != null) {
      marshalRecord.characters(c_id);
    }
 else {
      String value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),bytes,session);
      marshalRecord.characters(value);
    }
  }
 else {
    if (marshalRecord.isXOPPackage() && !xmlBinaryDataMapping.shouldInlineBinaryData()) {
      XPathFragment lastFrag=((XMLField)xmlBinaryDataMapping.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.xmlBinaryDataMapping.getMimeType(object),lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
 else       if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler)objectValue,lastFrag.getLocalName(),lastFrag.getNamespaceURI());
        if (c_id == null) {
          bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object)).getData();
        }
      }
 else {
        XMLBinaryDataHelper.EncodedData data=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object));
        bytes=data.getData();
        c_id=marshaller.getAttachmentMarshaller().addMtomAttachment(bytes,0,bytes.length,data.getMimeType(),lastFrag.getLocalName(),lastFrag.getNamespaceURI());
      }
      if (c_id == null) {
        String value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),bytes,session);
        marshalRecord.characters(value);
      }
 else {
        String xopPrefix=null;
        if (namespaceResolver != null) {
          xopPrefix=namespaceResolver.resolveNamespaceURI(XMLConstants.XOP_URL);
        }
        boolean addDeclaration=false;
        if (xopPrefix == null || namespaceResolver == null) {
          addDeclaration=true;
          xopPrefix=XMLConstants.XOP_PREFIX;
          namespaceResolver=new NamespaceResolver();
          namespaceResolver.put(xopPrefix,XMLConstants.XOP_URL);
        }
        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(xopInclude,namespaceResolver);
      }
    }
 else {
      String value=XMLConstants.EMPTY_STRING;
      if ((objectValue.getClass() == ClassConstants.ABYTE) || (objectValue.getClass() == ClassConstants.APBYTE)) {
        value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),objectValue,session);
      }
 else {
        byte[] bytes=XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(objectValue,marshaller,xmlBinaryDataMapping.getMimeType(object)).getData();
        value=getValueToWrite(((XMLField)xmlBinaryDataMapping.getField()).getSchemaType(),bytes,session);
      }
      marshalRecord.characters(value);
    }
  }
  if (!xPathFragment.isSelfFragment()) {
    marshalRecord.endElement(xPathFragment,namespaceResolver);
  }
  return true;
}