Program: 64378
Project: 64378
Buggy source:
public boolean addXsiTypeAndClassIndicatorIfRequired(org.eclipse.persistence.internal.oxm.record.XMLRecord record,Descriptor xmlDescriptor,Descriptor referenceDescriptor,Field xmlField,boolean isRootElement){
  if (descriptor.hasInheritance() && !xsiTypeIndicatorField) {
    xmlDescriptor.getInheritancePolicy().addClassIndicatorFieldToRow((XMLRecord)record);
    return true;
  }
  QName leafType=null;
  if (xmlField != null) {
    leafType=xmlField.getLeafElementType();
    XMLSchemaReference xmlRef=xmlDescriptor.getSchemaReference();
    if (xmlRef != null) {
      if (leafType == null) {
        if (xmlRef.getType() == XMLSchemaReference.ELEMENT) {
          return false;
        }
        if (referenceDescriptor == null) {
          writeXsiTypeAttribute(xmlDescriptor,record,xmlRef,isRootElement);
          return true;
        }
      }
 else       if (((xmlRef.getType() == XMLSchemaReference.COMPLEX_TYPE) || (xmlRef.getType() == XMLSchemaReference.SIMPLE_TYPE)) && xmlRef.getSchemaContext() != null && xmlRef.isGlobalDefinition()) {
        QName ctxQName=xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
        if (!ctxQName.equals(leafType)) {
          writeXsiTypeAttribute(xmlDescriptor,record,xmlRef,isRootElement);
          return true;
        }
      }
    }
  }
  if (referenceDescriptor != null && referenceDescriptor == xmlDescriptor) {
    return false;
  }
  if (xmlDescriptor.hasInheritance() && !xmlDescriptor.getInheritancePolicy().isRootParentDescriptor()) {
    CoreInheritancePolicy inheritancePolicy=xmlDescriptor.getInheritancePolicy();
    Field indicatorField=(Field)inheritancePolicy.getClassIndicatorField();
    if (indicatorField != null && xsiTypeIndicatorField) {
      Object classIndicatorValueObject=inheritancePolicy.getClassIndicatorMapping().get(xmlDescriptor.getJavaClass());
      String classIndicatorUri=null;
      String classIndicatorLocal=null;
      String classIndicatorPrefix=null;
      if (classIndicatorValueObject instanceof QName) {
        QName classIndicatorQName=(QName)classIndicatorValueObject;
        classIndicatorUri=classIndicatorQName.getNamespaceURI();
        classIndicatorLocal=classIndicatorQName.getLocalPart();
        classIndicatorPrefix=classIndicatorQName.getPrefix();
      }
 else {
        String classIndicatorValue=(String)inheritancePolicy.getClassIndicatorMapping().get(xmlDescriptor.getJavaClass());
        int nsindex=classIndicatorValue.indexOf(Constants.COLON);
        String prefix=null;
        if (nsindex != -1) {
          classIndicatorLocal=classIndicatorValue.substring(nsindex + 1);
          prefix=classIndicatorValue.substring(0,nsindex);
        }
 else {
          classIndicatorLocal=classIndicatorValue;
        }
        classIndicatorUri=xmlDescriptor.getNonNullNamespaceResolver().resolveNamespacePrefix(prefix);
      }
      if (leafType == null || isRootElement && record.getMarshaller().getMediaType() == MediaType.APPLICATION_JSON && !record.getMarshaller().isIncludeRoot() || !(leafType.getLocalPart().equals(classIndicatorLocal)) || (classIndicatorUri == null && (leafType.getNamespaceURI() != null && leafType.getNamespaceURI().length() > 0)) || (classIndicatorUri != null && !classIndicatorUri.equals(leafType.getNamespaceURI()))) {
        if (inheritancePolicy.hasClassExtractor()) {
          inheritancePolicy.addClassIndicatorFieldToRow((XMLRecord)record);
        }
 else {
          writeXsiTypeAttribute(xmlDescriptor,record,classIndicatorUri,classIndicatorLocal,classIndicatorPrefix,isRootElement);
        }
        return true;
      }
      return false;
    }
  }
  return false;
}

Fixed version (ground truth):
public boolean addXsiTypeAndClassIndicatorIfRequired(org.eclipse.persistence.internal.oxm.record.XMLRecord record,Descriptor xmlDescriptor,Descriptor referenceDescriptor,Field xmlField,boolean isRootElement){
  if (descriptor.hasInheritance() && !xsiTypeIndicatorField) {
    xmlDescriptor.getInheritancePolicy().addClassIndicatorFieldToRow((XMLRecord)record);
    return true;
  }
  QName leafType=null;
  if (xmlField != null) {
    leafType=xmlField.getLeafElementType();
    XMLSchemaReference xmlRef=xmlDescriptor.getSchemaReference();
    if (xmlRef != null) {
      if (leafType == null) {
        if (xmlRef.getType() == XMLSchemaReference.ELEMENT) {
          return false;
        }
        if (referenceDescriptor == null) {
          writeXsiTypeAttribute(xmlDescriptor,record,xmlRef,isRootElement);
          return true;
        }
      }
 else       if (((xmlRef.getType() == XMLSchemaReference.COMPLEX_TYPE) || (xmlRef.getType() == XMLSchemaReference.SIMPLE_TYPE)) && xmlRef.getSchemaContext() != null && xmlRef.isGlobalDefinition()) {
        QName ctxQName=xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
        if (!ctxQName.equals(leafType)) {
          writeXsiTypeAttribute(xmlDescriptor,record,xmlRef,isRootElement);
          return true;
        }
      }
    }
  }
  if (referenceDescriptor != null && referenceDescriptor == xmlDescriptor) {
    return false;
  }
  if (xmlDescriptor.hasInheritance() && !xmlDescriptor.getInheritancePolicy().isRootParentDescriptor()) {
    CoreInheritancePolicy inheritancePolicy=xmlDescriptor.getInheritancePolicy();
    Field indicatorField=(Field)inheritancePolicy.getClassIndicatorField();
    if (indicatorField != null && xsiTypeIndicatorField) {
      Object classIndicatorValueObject=inheritancePolicy.getClassIndicatorMapping().get(xmlDescriptor.getJavaClass());
      String classIndicatorUri=null;
      String classIndicatorLocal=null;
      String classIndicatorPrefix=null;
      if (classIndicatorValueObject instanceof QName) {
        QName classIndicatorQName=(QName)classIndicatorValueObject;
        classIndicatorUri=classIndicatorQName.getNamespaceURI();
        classIndicatorLocal=classIndicatorQName.getLocalPart();
        classIndicatorPrefix=classIndicatorQName.getPrefix();
      }
 else {
        String classIndicatorValue=(String)inheritancePolicy.getClassIndicatorMapping().get(xmlDescriptor.getJavaClass());
        int nsindex=classIndicatorValue.indexOf(Constants.COLON);
        String prefix=null;
        if (nsindex != -1) {
          classIndicatorLocal=classIndicatorValue.substring(nsindex + 1);
          prefix=classIndicatorValue.substring(0,nsindex);
        }
 else {
          classIndicatorLocal=classIndicatorValue;
        }
        classIndicatorUri=xmlDescriptor.getNonNullNamespaceResolver().resolveNamespacePrefix(prefix);
      }
      if (leafType == null || isRootElement && record.getMarshaller().getMediaType().isApplicationJSON() && !record.getMarshaller().isIncludeRoot() || !(leafType.getLocalPart().equals(classIndicatorLocal)) || (classIndicatorUri == null && (leafType.getNamespaceURI() != null && leafType.getNamespaceURI().length() > 0)) || (classIndicatorUri != null && !classIndicatorUri.equals(leafType.getNamespaceURI()))) {
        if (inheritancePolicy.hasClassExtractor()) {
          inheritancePolicy.addClassIndicatorFieldToRow((XMLRecord)record);
        }
 else {
          writeXsiTypeAttribute(xmlDescriptor,record,classIndicatorUri,classIndicatorLocal,classIndicatorPrefix,isRootElement);
        }
        return true;
      }
      return false;
    }
  }
  return false;
}