Program: 42447
Project: 42447
Buggy source:
@Override protected void fillDocument(Document doc,PageMetadata pageMetadata){
  super.fillDocument(doc,pageMetadata);
  if (!(pageMetadata instanceof SeoPageMetadata)) {
    return;
  }
  SeoPageMetadata seoPageMetadata=(SeoPageMetadata)pageMetadata;
  Element useExtraDescriptionsElement=new Element(USE_EXTRA_DESCRIPTIONS_ELEMENT_NAME);
  useExtraDescriptionsElement.setText(String.valueOf(seoPageMetadata.isUseExtraDescriptions()));
  doc.getRootElement().addContent(useExtraDescriptionsElement);
  ApsProperties descriptions=seoPageMetadata.getDescriptions();
  if (null != descriptions && descriptions.size() > 0) {
    Element descriptionsElement=new Element(DESCRIPTIONS_ELEMENT_NAME);
    doc.getRootElement().addContent(descriptionsElement);
    Iterator<Object> iterator=descriptions.keySet().iterator();
    while (iterator.hasNext()) {
      String langCode=(String)iterator.next();
      Element extraDescriptionElement=new Element(DESCRIPTION_ELEMENT_NAME);
      extraDescriptionElement.setAttribute(DESCRIPTION_LANG_ATTRIBUTE_NAME,langCode);
      extraDescriptionElement.setText(descriptions.getProperty(langCode));
      descriptionsElement.addContent(extraDescriptionElement);
    }
  }
  if (null != seoPageMetadata.getFriendlyCode() && seoPageMetadata.getFriendlyCode().trim().length() > 0) {
    Element friendlyCodeElement=new Element(FRIENDLY_CODE_ELEMENT_NAME);
    friendlyCodeElement.setText(seoPageMetadata.getFriendlyCode().trim());
    doc.getRootElement().addContent(friendlyCodeElement);
  }
  if (null != seoPageMetadata.getComplexParameters()) {
    Element complexConfigElement=new Element(COMPLEX_PARAMS_ELEMENT_NAME);
    this.addComplexParameters(complexConfigElement,seoPageMetadata.getComplexParameters());
    doc.getRootElement().addContent(complexConfigElement);
  }
}

Fixed version (ground truth):
@Override protected void fillDocument(Document doc,PageMetadata pageMetadata){
  super.fillDocument(doc,pageMetadata);
  if (!(pageMetadata instanceof SeoPageMetadata)) {
    return;
  }
  SeoPageMetadata seoPageMetadata=(SeoPageMetadata)pageMetadata;
  Element useExtraDescriptionsElement=new Element(USE_EXTRA_DESCRIPTIONS_ELEMENT_NAME);
  useExtraDescriptionsElement.setText(String.valueOf(seoPageMetadata.isUseExtraDescriptions()));
  doc.getRootElement().addContent(useExtraDescriptionsElement);
  ApsProperties descriptions=seoPageMetadata.getDescriptions();
  if (null != descriptions && descriptions.size() > 0) {
    Element descriptionsElement=new Element(DESCRIPTIONS_ELEMENT_NAME);
    doc.getRootElement().addContent(descriptionsElement);
    Iterator<Object> iterator=descriptions.keySet().iterator();
    while (iterator.hasNext()) {
      String langCode=(String)iterator.next();
      Element extraDescriptionElement=new Element(DESCRIPTION_ELEMENT_NAME);
      extraDescriptionElement.setAttribute(DESCRIPTION_LANG_ATTRIBUTE_NAME,langCode);
      PageMetatag metatag=(PageMetatag)descriptions.get(langCode);
      extraDescriptionElement.setAttribute(USE_DEFAULT_LANG_ELEMENT_NAME,String.valueOf(metatag.isUseDefaultLangValue()));
      extraDescriptionElement.setText(metatag.getValue());
      descriptionsElement.addContent(extraDescriptionElement);
    }
  }
  if (null != seoPageMetadata.getFriendlyCode() && seoPageMetadata.getFriendlyCode().trim().length() > 0) {
    Element friendlyCodeElement=new Element(FRIENDLY_CODE_ELEMENT_NAME);
    friendlyCodeElement.setText(seoPageMetadata.getFriendlyCode().trim());
    doc.getRootElement().addContent(friendlyCodeElement);
  }
  if (null != seoPageMetadata.getComplexParameters()) {
    Element complexConfigElement=new Element(COMPLEX_PARAMS_ELEMENT_NAME);
    this.addComplexParameters(complexConfigElement,seoPageMetadata.getComplexParameters());
    doc.getRootElement().addContent(complexConfigElement);
  }
}