Program: 101982
Project: 101982
Buggy source:
/** 
 * Move the existing child to the appropriate index in the docParent so that it is consistent with the schema
 * @param documentElement
 * @param xsdComponent
 * @return true if document element was moved.
 */
private boolean moveIfNotAtSameIndex(final XmlDocumentEntity documentElement,final XSDComponent xsdComponent) throws ModelerCoreException {
  boolean moved=false;
  final XmlDocumentEntity docParent=(XmlDocumentEntity)documentElement.eContainer();
  final XSDComponent schemaParent=(XSDComponent)xsdComponent.eContainer();
  final int docIndex=getIndexOfChild(docParent,documentElement);
  final int schemaIndex=getIndexOfChild(schemaParent,xsdComponent);
  if (docIndex == -1)   throw new ModelerCoreException(XmlDocumentPlugin.Util.getString("String_Node_Str") + xsdComponent.toString());
 else   if (schemaIndex == -1)   throw new ModelerCoreException(XmlDocumentPlugin.Util.getString("String_Node_Str") + documentElement.toString());
  if (docIndex == 0 && schemaIndex == 0)   return moved;
  final EList docList=(EList)docParent.eGet(documentElement.eContainmentFeature());
  EList schemaList=null;
  if (schemaParent instanceof XSDParticle || schemaParent instanceof XSDAttributeUse)   schemaList=(EList)schemaParent.eContainer().eGet(schemaParent.eContainmentFeature());
 else   schemaList=(EList)schemaParent.eGet(xsdComponent.eContainmentFeature());
  if (schemaIndex > 0 && docList.size() > 1) {
    final EObject tempSchemaElement=(EObject)schemaList.get((schemaIndex - 1));
    final Iterator docChildren=docList.iterator();
    boolean found=false;
    while (docChildren.hasNext() && !found) {
      final EObject docChild=(EObject)docChildren.next();
      final EObject schemaRef=findSchemaReference(docChild);
      if (schemaRef != null && schemaRef == tempSchemaElement) {
        found=true;
        final int temp=getIndexOfChild(docParent,docChild) + 1;
        if (temp != docIndex) {
          me.move(docParent,documentElement,temp);
          moved=true;
        }
      }
    }
  }
 else   if (schemaIndex == 0 && docList.size() > 1) {
    int foundIndex=Integer.MAX_VALUE;
    final Iterator docChildren=docList.iterator();
    while (docChildren.hasNext()) {
      final EObject docChild=(EObject)docChildren.next();
      final EObject schemaRef=findSchemaReference(docChild);
      if (schemaRef != null && schemaRef != xsdComponent && schemaList.contains(schemaRef)) {
        final int temp=getIndexOfChild(docParent,docChild);
        if (temp < foundIndex)         foundIndex=temp;
      }
    }
    if (foundIndex < Integer.MAX_VALUE && foundIndex != docIndex) {
      me.move(docParent,documentElement,foundIndex);
      moved=true;
    }
  }
  return moved;
}

Fixed version (ground truth):
/** 
 * Move the existing child to the appropriate index in the docParent so that it is consistent with the schema
 * @param documentElement
 * @param xsdComponent
 * @return true if document element was moved.
 */
private boolean moveIfNotAtSameIndex(final XmlDocumentEntity documentElement,final XSDComponent xsdComponent) throws ModelerCoreException {
  boolean moved=false;
  final XmlDocumentEntity docParent=(XmlDocumentEntity)documentElement.eContainer();
  final XSDComponent schemaParent=(XSDComponent)xsdComponent.eContainer();
  final int docIndex=getIndexOfChild(docParent,documentElement);
  final int schemaIndex=getIndexOfChild(schemaParent,xsdComponent);
  if (docIndex == -1)   throw new ModelerCoreException(XmlDocumentPlugin.Util.getString("String_Node_Str") + xsdComponent.toString());
 else   if (schemaIndex == -1)   throw new ModelerCoreException(XmlDocumentPlugin.Util.getString("String_Node_Str") + documentElement.toString());
  if (docIndex == 0 && schemaIndex == 0)   return moved;
  final EList docList=(EList)docParent.eGet(documentElement.eContainmentFeature());
  EList schemaList=null;
  if (schemaParent instanceof XSDParticle || schemaParent instanceof XSDAttributeUse)   schemaList=(EList)schemaParent.eContainer().eGet(schemaParent.eContainmentFeature());
 else   schemaList=(EList)schemaParent.eGet(xsdComponent.eContainmentFeature());
  if (schemaIndex > 0 && docList.size() > 1) {
    final EObject tempSchemaElement=(EObject)schemaList.get((schemaIndex - 1));
    final Iterator docChildren=docList.iterator();
    boolean found=false;
    while (docChildren.hasNext() && !found) {
      final EObject docChild=(EObject)docChildren.next();
      final EObject schemaRef=findSchemaReference(docChild);
      if (schemaRef != null && schemaRef == tempSchemaElement) {
        found=true;
        final int temp=getIndexOfChild(docParent,docChild) + 1;
        if (temp != docIndex) {
          getModelEditor().move(docParent,documentElement,temp);
          moved=true;
        }
      }
    }
  }
 else   if (schemaIndex == 0 && docList.size() > 1) {
    int foundIndex=Integer.MAX_VALUE;
    final Iterator docChildren=docList.iterator();
    while (docChildren.hasNext()) {
      final EObject docChild=(EObject)docChildren.next();
      final EObject schemaRef=findSchemaReference(docChild);
      if (schemaRef != null && schemaRef != xsdComponent && schemaList.contains(schemaRef)) {
        final int temp=getIndexOfChild(docParent,docChild);
        if (temp < foundIndex)         foundIndex=temp;
      }
    }
    if (foundIndex < Integer.MAX_VALUE && foundIndex != docIndex) {
      getModelEditor().move(docParent,documentElement,foundIndex);
      moved=true;
    }
  }
  return moved;
}