Program: 11857
Project: 11857
Buggy source:
/** 
 * Check if the values of the forward references have been set (they may have been set due to a bi-directional reference being set).  If not, set them. If this is called during end document processing, errors should be diagnosed. If it is called in the middle of a document,  we need to clean up the forward reference lists to avoid reprocessing resolved references again later.
 */
protected void handleForwardReferences(boolean isEndDocument){
  for (Iterator<InternalEObject> i=sameDocumentProxies.iterator(); i.hasNext(); ) {
    InternalEObject proxy=i.next();
    LOOP:     for (    EReference eReference : proxy.eClass().getEAllReferences()) {
      EReference oppositeEReference=eReference.getEOpposite();
      if (oppositeEReference != null && proxy.eIsSet(eReference)) {
        EObject resolvedEObject=xmlResource.getEObject(proxy.eProxyURI().fragment());
        if (resolvedEObject != null) {
          if (!isEndDocument) {
            i.remove();
          }
          EObject proxyHolder=(EObject)(eReference.isMany() ? ((List<?>)proxy.eGet(eReference)).get(0) : proxy.eGet(eReference));
          if (oppositeEReference.isMany()) {
            InternalEList<?> holderContents=(InternalEList<?>)proxyHolder.eGet(oppositeEReference);
            List<?> basicHolderContents=holderContents.basicList();
            int resolvedEObjectIndex=basicHolderContents.indexOf(resolvedEObject);
            if (resolvedEObjectIndex != -1) {
              int proxyIndex=basicHolderContents.indexOf(proxy);
              holderContents.move(proxyIndex,resolvedEObjectIndex);
              holderContents.remove(proxyIndex > resolvedEObjectIndex ? proxyIndex - 1 : proxyIndex + 1);
              break LOOP;
            }
          }
          if (eReference.isMany() ? !((InternalEList<?>)resolvedEObject.eGet(eReference)).basicList().contains(proxyHolder) : resolvedEObject.eGet(eReference) != proxyHolder) {
            if (oppositeEReference.isMany()) {
              @SuppressWarnings("String_Node_Str") InternalEList<EObject> proxyHolderList=(InternalEList<EObject>)proxyHolder.eGet(oppositeEReference);
              proxyHolderList.setUnique(proxyHolderList.indexOf(proxy),resolvedEObject);
            }
 else {
              proxyHolder.eSet(oppositeEReference,resolvedEObject);
            }
          }
        }
        break;
      }
    }
  }
  for (Iterator<SingleReference> i=forwardSingleReferences.iterator(); i.hasNext(); ) {
    SingleReference ref=i.next();
    EObject obj=xmlResource.getEObject((String)ref.getValue());
    if (obj != null) {
      if (!isEndDocument) {
        i.remove();
      }
      EStructuralFeature feature=ref.getFeature();
      setFeatureValue(ref.getObject(),feature,obj,ref.getPosition());
    }
 else     if (isEndDocument) {
      error(new UnresolvedReferenceException((String)ref.getValue(),getLocation(),ref.getLineNumber(),ref.getColumnNumber()));
    }
  }
  for (Iterator<ManyReference> i=forwardManyReferences.iterator(); i.hasNext(); ) {
    ManyReference ref=i.next();
    Object[] values=ref.getValues();
    boolean failure=false;
    for (int j=0, l=values.length; j < l; j++) {
      String id=(String)values[j];
      EObject obj=xmlResource.getEObject(id);
      values[j]=obj;
      if (obj == null) {
        failure=true;
        if (isEndDocument) {
          error(new UnresolvedReferenceException(id,getLocation(),ref.getLineNumber(),ref.getColumnNumber()));
        }
      }
    }
    if (!failure) {
      if (!isEndDocument) {
        i.remove();
      }
      setFeatureValues(ref);
    }
 else     if (isEndDocument) {
      setFeatureValues(ref);
    }
  }
}

Fixed version (ground truth):
/** 
 * Check if the values of the forward references have been set (they may have been set due to a bidirectional reference being set).  If not, set them. If this is called during end document processing, errors should be diagnosed. If it is called in the middle of a document,  we need to clean up the forward reference lists to avoid processing resolved references again later.
 */
protected void handleForwardReferences(boolean isEndDocument){
  for (Iterator<InternalEObject> i=sameDocumentProxies.iterator(); i.hasNext(); ) {
    InternalEObject proxy=i.next();
    LOOP:     for (    EReference eReference : proxy.eClass().getEAllReferences()) {
      EReference oppositeEReference=eReference.getEOpposite();
      if (oppositeEReference != null && proxy.eIsSet(eReference)) {
        EObject resolvedEObject=xmlResource.getEObject(proxy.eProxyURI().fragment());
        if (resolvedEObject != null) {
          if (!isEndDocument) {
            i.remove();
          }
          EObject proxyHolder=(EObject)(eReference.isMany() ? ((List<?>)proxy.eGet(eReference)).get(0) : proxy.eGet(eReference));
          if (oppositeEReference.isMany()) {
            InternalEList<?> holderContents=(InternalEList<?>)proxyHolder.eGet(oppositeEReference);
            List<?> basicHolderContents=holderContents.basicList();
            int resolvedEObjectIndex=basicHolderContents.indexOf(resolvedEObject);
            if (resolvedEObjectIndex != -1) {
              int proxyIndex=basicHolderContents.indexOf(proxy);
              holderContents.move(proxyIndex,resolvedEObjectIndex);
              holderContents.remove(proxyIndex > resolvedEObjectIndex ? proxyIndex - 1 : proxyIndex + 1);
              break LOOP;
            }
          }
          if (eReference.isMany() ? !((InternalEList<?>)resolvedEObject.eGet(eReference)).basicList().contains(proxyHolder) : resolvedEObject.eGet(eReference) != proxyHolder) {
            if (oppositeEReference.isMany()) {
              @SuppressWarnings("String_Node_Str") InternalEList<EObject> proxyHolderList=(InternalEList<EObject>)proxyHolder.eGet(oppositeEReference);
              proxyHolderList.setUnique(proxyHolderList.indexOf(proxy),resolvedEObject);
            }
 else {
              proxyHolder.eSet(oppositeEReference,resolvedEObject);
            }
          }
        }
        break;
      }
    }
  }
  for (Iterator<SingleReference> i=forwardSingleReferences.iterator(); i.hasNext(); ) {
    SingleReference ref=i.next();
    EObject obj=xmlResource.getEObject((String)ref.getValue());
    if (obj != null) {
      if (!isEndDocument) {
        i.remove();
      }
      EStructuralFeature feature=ref.getFeature();
      setFeatureValue(ref.getObject(),feature,obj,ref.getPosition());
    }
 else     if (isEndDocument) {
      error(new UnresolvedReferenceException((String)ref.getValue(),getLocation(),ref.getLineNumber(),ref.getColumnNumber()));
    }
  }
  for (Iterator<ManyReference> i=forwardManyReferences.iterator(); i.hasNext(); ) {
    ManyReference ref=i.next();
    Object[] values=ref.getValues();
    boolean failure=false;
    for (int j=0, l=values.length; j < l; j++) {
      String id=(String)values[j];
      EObject obj=xmlResource.getEObject(id);
      values[j]=obj;
      if (obj == null) {
        failure=true;
        if (isEndDocument) {
          error(new UnresolvedReferenceException(id,getLocation(),ref.getLineNumber(),ref.getColumnNumber()));
        }
      }
    }
    if (!failure) {
      if (!isEndDocument) {
        i.remove();
      }
      setFeatureValues(ref);
    }
 else     if (isEndDocument) {
      setFeatureValues(ref);
    }
  }
}