Program: 64038
Project: 64038
Buggy source:
/** 
 * INTERNAL
 * @since EclipseLink 2.5.0
 */
public boolean addXsiTypeAndClassIndicatorIfRequired(Descriptor descriptor,Descriptor referenceDescriptor,Field xmlField,Object originalObject,Object obj,boolean wasXMLRoot,boolean isRootElement){
  if (wasXMLRoot) {
    XMLSchemaReference xmlRef=descriptor.getSchemaReference();
    if (descriptor != null) {
      Root xr=(Root)originalObject;
      if (xmlRef == null) {
        return false;
      }
      String xmlRootLocalName=xr.getLocalName();
      String xmlRootUri=xr.getNamespaceURI();
      XPathQName qName=new XPathQName(xmlRootUri,xmlRootLocalName,namespaceAware);
      Descriptor xdesc=marshaller.getContext().getDescriptor(qName);
      if (xdesc != null) {
        boolean writeTypeAttribute=xdesc.getJavaClass() != descriptor.getJavaClass();
        if (writeTypeAttribute) {
          writeXsiTypeAttribute(descriptor,xmlRef,isRootElement);
          return true;
        }
        return false;
      }
      if (xr.getDeclaredType() != null && xr.getDeclaredType() == xr.getObject().getClass()) {
        return false;
      }
      boolean writeTypeAttribute=true;
      int tableSize=descriptor.getTableNames().size();
      for (int i=0; i < tableSize; i++) {
        if (!writeTypeAttribute) {
          return false;
        }
        String defaultRootQualifiedName=(String)descriptor.getTableNames().get(i);
        if (defaultRootQualifiedName != null) {
          String defaultRootLocalName=null;
          String defaultRootUri=null;
          int colonIndex=defaultRootQualifiedName.indexOf(Constants.COLON);
          if (colonIndex > 0) {
            String defaultRootPrefix=defaultRootQualifiedName.substring(0,colonIndex);
            defaultRootLocalName=defaultRootQualifiedName.substring(colonIndex + 1);
            if (descriptor.getNamespaceResolver() != null) {
              defaultRootUri=descriptor.getNamespaceResolver().resolveNamespacePrefix(defaultRootPrefix);
            }
          }
 else {
            defaultRootLocalName=defaultRootQualifiedName;
          }
          if (xmlRootLocalName != null) {
            if ((((defaultRootLocalName == null) && (xmlRootLocalName == null)) || (defaultRootLocalName.equals(xmlRootLocalName))) && (((defaultRootUri == null) && (xmlRootUri == null)) || ((xmlRootUri != null) && (defaultRootUri != null) && (defaultRootUri.equals(xmlRootUri))))) {
              return false;
            }
          }
        }
 else {
          if (xmlRootLocalName == null) {
            return false;
          }
        }
      }
      if (writeTypeAttribute && xmlRef != null) {
        writeXsiTypeAttribute(descriptor,xmlRef,isRootElement);
        return true;
      }
    }
    return false;
  }
 else {
    return addXsiTypeAndClassIndicatorIfRequired(descriptor,referenceDescriptor,xmlField,isRootElement);
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL
 * @since EclipseLink 2.5.0
 */
public boolean addXsiTypeAndClassIndicatorIfRequired(Descriptor descriptor,Descriptor referenceDescriptor,Field xmlField,Object originalObject,Object obj,boolean wasXMLRoot,boolean isRootElement){
  if (wasXMLRoot) {
    XMLSchemaReference xmlRef=descriptor.getSchemaReference();
    if (descriptor != null) {
      Root xr=(Root)originalObject;
      if (xmlRef == null) {
        return false;
      }
      if (xr.getDeclaredType() != null && xr.getDeclaredType() == xr.getObject().getClass()) {
        return false;
      }
      String xmlRootLocalName=xr.getLocalName();
      String xmlRootUri=xr.getNamespaceURI();
      XPathQName qName=new XPathQName(xmlRootUri,xmlRootLocalName,namespaceAware);
      Descriptor xdesc=marshaller.getContext().getDescriptor(qName);
      if (xdesc != null) {
        boolean writeTypeAttribute=xdesc.getJavaClass() != descriptor.getJavaClass();
        if (writeTypeAttribute) {
          writeXsiTypeAttribute(descriptor,xmlRef,isRootElement);
          return true;
        }
        return false;
      }
      boolean writeTypeAttribute=true;
      int tableSize=descriptor.getTableNames().size();
      for (int i=0; i < tableSize; i++) {
        if (!writeTypeAttribute) {
          return false;
        }
        String defaultRootQualifiedName=(String)descriptor.getTableNames().get(i);
        if (defaultRootQualifiedName != null) {
          String defaultRootLocalName=null;
          String defaultRootUri=null;
          int colonIndex=defaultRootQualifiedName.indexOf(Constants.COLON);
          if (colonIndex > 0) {
            String defaultRootPrefix=defaultRootQualifiedName.substring(0,colonIndex);
            defaultRootLocalName=defaultRootQualifiedName.substring(colonIndex + 1);
            if (descriptor.getNamespaceResolver() != null) {
              defaultRootUri=descriptor.getNamespaceResolver().resolveNamespacePrefix(defaultRootPrefix);
            }
          }
 else {
            defaultRootLocalName=defaultRootQualifiedName;
          }
          if (xmlRootLocalName != null) {
            if ((((defaultRootLocalName == null) && (xmlRootLocalName == null)) || (defaultRootLocalName.equals(xmlRootLocalName))) && (((defaultRootUri == null) && (xmlRootUri == null)) || ((xmlRootUri != null) && (defaultRootUri != null) && (defaultRootUri.equals(xmlRootUri))))) {
              return false;
            }
          }
        }
 else {
          if (xmlRootLocalName == null) {
            return false;
          }
        }
      }
      if (writeTypeAttribute && xmlRef != null) {
        writeXsiTypeAttribute(descriptor,xmlRef,isRootElement);
        return true;
      }
    }
    return false;
  }
 else {
    return addXsiTypeAndClassIndicatorIfRequired(descriptor,referenceDescriptor,xmlField,isRootElement);
  }
}