Program: 65710
Project: 65710
Buggy source:
public boolean addXsiTypeAndClassIndicatorIfRequired(XMLRecord record,XMLDescriptor xmlDescriptor,XMLDescriptor referenceDescriptor,XMLField xmlField,boolean addToNamespaceResolver){
  boolean xsiTypeIndicatorField=false;
  if (xmlDescriptor.hasInheritance()) {
    XMLField indicatorField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
    if (indicatorField != null) {
      if (indicatorField.getLastXPathFragment().getNamespaceURI() != null && indicatorField.getLastXPathFragment().getNamespaceURI().equals(XMLConstants.SCHEMA_INSTANCE_URL) && indicatorField.getLastXPathFragment().getLocalName().equals(XMLConstants.SCHEMA_TYPE_ATTRIBUTE)) {
        xsiTypeIndicatorField=true;
      }
      if (!xsiTypeIndicatorField) {
        xmlDescriptor.getInheritancePolicy().addClassIndicatorFieldToRow(record);
      }
    }
  }
  QName leafType=null;
  if (xmlField != null) {
    leafType=xmlField.getLeafElementType();
    XMLSchemaReference xmlRef=xmlDescriptor.getSchemaReference();
    if (xmlRef != null) {
      if (leafType == null && xmlRef.getType() == XMLSchemaReference.ELEMENT) {
        return false;
      }
      String typeValue=getTypeValueToWrite(record,xmlRef,addToNamespaceResolver);
      if (leafType == null && referenceDescriptor == null) {
        writeXsiTypeAttribute(xmlDescriptor,record,typeValue,addToNamespaceResolver);
        return true;
      }
      if (((xmlRef.getType() == XMLSchemaReference.COMPLEX_TYPE) || (xmlRef.getType() == XMLSchemaReference.SIMPLE_TYPE)) && xmlRef.getSchemaContext() != null && xmlRef.isGlobalDefinition()) {
        QName ctxQName=xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
        if (leafType != null) {
          if (!ctxQName.equals(leafType)) {
            writeXsiTypeAttribute(xmlDescriptor,record,typeValue,addToNamespaceResolver);
            return true;
          }
        }
      }
    }
  }
  if (referenceDescriptor != null && referenceDescriptor == xmlDescriptor) {
    return false;
  }
  if (xmlDescriptor.hasInheritance() && !xmlDescriptor.getInheritancePolicy().isRootParentDescriptor()) {
    XMLField indicatorField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
    if (indicatorField != null && xsiTypeIndicatorField) {
      String classIndicatorValue=(String)xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(xmlDescriptor.getJavaClass());
      int nsindex=classIndicatorValue.indexOf(XMLConstants.COLON);
      String localName=null;
      String prefix=null;
      if (nsindex != -1) {
        localName=classIndicatorValue.substring(nsindex + 1);
        prefix=classIndicatorValue.substring(0,nsindex);
      }
 else {
        localName=classIndicatorValue;
      }
      String namespaceURI=xmlDescriptor.getNonNullNamespaceResolver().resolveNamespacePrefix(prefix);
      QName classIndicatorQName=new QName(namespaceURI,localName);
      if (leafType == null || !classIndicatorQName.equals(leafType)) {
        xmlDescriptor.getInheritancePolicy().addClassIndicatorFieldToRow(record);
        return true;
      }
      return false;
    }
  }
  return false;
}

Fixed version (ground truth):
public boolean addXsiTypeAndClassIndicatorIfRequired(XMLRecord record,XMLDescriptor xmlDescriptor,XMLDescriptor referenceDescriptor,XMLField xmlField,boolean addToNamespaceResolver){
  boolean xsiTypeIndicatorField=false;
  if (xmlDescriptor.hasInheritance()) {
    XMLField indicatorField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
    if (indicatorField != null) {
      if (indicatorField.getLastXPathFragment().getNamespaceURI() != null && indicatorField.getLastXPathFragment().getNamespaceURI().equals(XMLConstants.SCHEMA_INSTANCE_URL) && indicatorField.getLastXPathFragment().getLocalName().equals(XMLConstants.SCHEMA_TYPE_ATTRIBUTE)) {
        xsiTypeIndicatorField=true;
      }
      if (!xsiTypeIndicatorField) {
        xmlDescriptor.getInheritancePolicy().addClassIndicatorFieldToRow(record);
      }
    }
  }
  QName leafType=null;
  if (xmlField != null) {
    leafType=xmlField.getLeafElementType();
    XMLSchemaReference xmlRef=xmlDescriptor.getSchemaReference();
    if (xmlRef != null) {
      if (leafType == null && xmlRef.getType() == XMLSchemaReference.ELEMENT) {
        return false;
      }
      String typeValue=getTypeValueToWrite(record,xmlDescriptor,xmlRef,addToNamespaceResolver);
      if (leafType == null && referenceDescriptor == null) {
        writeXsiTypeAttribute(xmlDescriptor,record,typeValue,addToNamespaceResolver);
        return true;
      }
      if (((xmlRef.getType() == XMLSchemaReference.COMPLEX_TYPE) || (xmlRef.getType() == XMLSchemaReference.SIMPLE_TYPE)) && xmlRef.getSchemaContext() != null && xmlRef.isGlobalDefinition()) {
        QName ctxQName=xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
        if (leafType != null) {
          if (!ctxQName.equals(leafType)) {
            writeXsiTypeAttribute(xmlDescriptor,record,typeValue,addToNamespaceResolver);
            return true;
          }
        }
      }
    }
  }
  if (referenceDescriptor != null && referenceDescriptor == xmlDescriptor) {
    return false;
  }
  if (xmlDescriptor.hasInheritance() && !xmlDescriptor.getInheritancePolicy().isRootParentDescriptor()) {
    XMLField indicatorField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
    if (indicatorField != null && xsiTypeIndicatorField) {
      String classIndicatorValue=(String)xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(xmlDescriptor.getJavaClass());
      int nsindex=classIndicatorValue.indexOf(XMLConstants.COLON);
      String localName=null;
      String prefix=null;
      if (nsindex != -1) {
        localName=classIndicatorValue.substring(nsindex + 1);
        prefix=classIndicatorValue.substring(0,nsindex);
      }
 else {
        localName=classIndicatorValue;
      }
      String namespaceURI=xmlDescriptor.getNonNullNamespaceResolver().resolveNamespacePrefix(prefix);
      QName classIndicatorQName=new QName(namespaceURI,localName);
      if (leafType == null || !classIndicatorQName.equals(leafType)) {
        xmlDescriptor.getInheritancePolicy().addClassIndicatorFieldToRow(record);
        return true;
      }
      return false;
    }
  }
  return false;
}