Program: 74381
Project: 74381
Buggy source:
private void _removeObjects(CompositeEntity host) throws TransformationException {
  try {
    NamedObj replacement=_replacementToHost.getKey(host);
    Map<NamedObj,Boolean> childrenToRemove=new HashMap<NamedObj,Boolean>();
    Set<NamedObj> newChildren=new HashSet<NamedObj>();
    host.workspace().getReadAccess();
    Collection<?> children=GTTools.getChildren(host,false,true,true,true);
    while (!children.isEmpty()) {
      childrenToRemove.clear();
      for (      Object childObject : children) {
        NamedObj child=(NamedObj)childObject;
        NamedObj replacementChild=(NamedObj)_replacementToHost.getKey(child);
        NamedObj patternChild=(NamedObj)_matchResult.getKey(child);
        if (replacementChild == null && patternChild != null && !_isToBeCreated(patternChild)) {
          Boolean shallowRemoval=patternChild instanceof CompositeEntity ? Boolean.TRUE : Boolean.FALSE;
          childrenToRemove.put(child,shallowRemoval);
        }
 else         if (replacementChild != null && replacementChild.getContainer() != replacement) {
          Boolean shallowRemoval=replacementChild instanceof CompositeEntity ? Boolean.TRUE : Boolean.FALSE;
          childrenToRemove.put(child,shallowRemoval);
        }
      }
      newChildren.clear();
      for (      Map.Entry<NamedObj,Boolean> entry : childrenToRemove.entrySet()) {
        NamedObj child=entry.getKey();
        Set<NamedObj> newlyAddedChildren=_removeObject(child,entry.getValue());
        if (newlyAddedChildren != null) {
          newChildren.addAll(newlyAddedChildren);
        }
      }
      children=newChildren;
    }
    for (    Object compositeChild : host.entityList(CompositeEntity.class)) {
      _removeObjects((CompositeEntity)compositeChild);
    }
  }
  finally {
    host.workspace().doneReading();
  }
}

Fixed version (ground truth):
private void _removeObjects(CompositeEntity host) throws TransformationException {
  try {
    NamedObj replacement=_replacementToHost.getKey(host);
    Map<NamedObj,Boolean> childrenToRemove=new HashMap<NamedObj,Boolean>();
    Set<NamedObj> newChildren=new HashSet<NamedObj>();
    host.workspace().getReadAccess();
    Collection<?> children=GTTools.getChildren(host,false,true,true,true);
    while (!children.isEmpty()) {
      childrenToRemove.clear();
      for (      Object childObject : children) {
        NamedObj child=(NamedObj)childObject;
        NamedObj replacementChild=(NamedObj)_replacementToHost.getKey(child);
        NamedObj patternChild=(NamedObj)_matchResult.getKey(child);
        if (replacementChild == null && patternChild != null && !_isToBeCreated(patternChild)) {
          Boolean shallowRemoval=patternChild instanceof CompositeEntity ? Boolean.TRUE : Boolean.FALSE;
          childrenToRemove.put(child,shallowRemoval);
        }
 else         if (replacementChild != null && replacementChild.getContainer() != replacement && replacementChild != patternChild) {
          Boolean shallowRemoval=replacementChild instanceof CompositeEntity ? Boolean.TRUE : Boolean.FALSE;
          childrenToRemove.put(child,shallowRemoval);
        }
      }
      newChildren.clear();
      for (      Map.Entry<NamedObj,Boolean> entry : childrenToRemove.entrySet()) {
        NamedObj child=entry.getKey();
        Set<NamedObj> newlyAddedChildren=_removeObject(child,entry.getValue());
        if (newlyAddedChildren != null) {
          newChildren.addAll(newlyAddedChildren);
        }
      }
      children=newChildren;
    }
    for (    Object compositeChild : host.entityList(CompositeEntity.class)) {
      _removeObjects((CompositeEntity)compositeChild);
    }
  }
  finally {
    host.workspace().doneReading();
  }
}