Program: 79211
Project: 79211
Buggy source:
/** 
 * Adjusts references to an element that is to be deleted. The element to be deleted is one that has references in the form of element reference properties on other elements. These other elements, called "clients", each contain a property of type element reference and that property refers to this element. Each reference is recorded with a "back pointer" from the referenced element to the client. That back pointer has both a pointer to the client element, and the property within that element that holds the reference. There are two algorithms to handle this reference property, which can be selected by <code>unresolveReference</code>. If <code>unresolveReference</code> is <code>true</code>, the reference property is unresolved. Otherwise, it's cleared.
 * @param element the element to be deleted
 * @param unresolveReference the flag indicating the reference property should be unresolved, instead of cleared
 * @throws SemanticException if an error occurs, but the operation should not fail under normal conditions
 * @see #adjustReferredClients(DesignElement)
 */
private void adjustReferenceClients(ReferenceableElement referred,boolean unresolveReference) throws SemanticException {
  List clients=new ArrayList(referred.getClientList());
  Iterator iter=clients.iterator();
  while (iter.hasNext()) {
    BackRef ref=(BackRef)iter.next();
    DesignElement client=ref.element;
    if (unresolveReference) {
      BackRefRecord record=new BackRefRecord(design,referred,client,ref.propName);
      getActivityStack().execute(record);
    }
 else {
      if (referred.isStyle()) {
        StyleCommand clientCmd=new StyleCommand(design,client);
        clientCmd.setStyleElement(null);
      }
 else {
        PropertyCommand cmd=new PropertyCommand(design,client);
        cmd.setProperty(ref.propName,null);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Adjusts references to an element that is to be deleted. The element to be deleted is one that has references in the form of element reference properties on other elements. These other elements, called "clients", each contain a property of type element reference and that property refers to this element. Each reference is recorded with a "back pointer" from the referenced element to the client. That back pointer has both a pointer to the client element, and the property within that element that holds the reference. There are two algorithms to handle this reference property, which can be selected by <code>unresolveReference</code>. If <code>unresolveReference</code> is <code>true</code>, the reference property is unresolved. Otherwise, it's cleared.
 * @param referred the element to be deleted
 * @param unresolveReference the flag indicating the reference property should be unresolved, instead of cleared
 * @throws SemanticException if an error occurs, but the operation should not fail under normal conditions
 * @see #adjustReferredClients(DesignElement)
 */
private void adjustReferenceClients(ReferenceableElement referred,boolean unresolveReference) throws SemanticException {
  List clients=new ArrayList(referred.getClientList());
  Iterator iter=clients.iterator();
  while (iter.hasNext()) {
    BackRef ref=(BackRef)iter.next();
    DesignElement client=ref.element;
    if (unresolveReference) {
      BackRefRecord record=new BackRefRecord(design,referred,client,ref.propName);
      getActivityStack().execute(record);
    }
 else {
      if (referred.isStyle()) {
        StyleCommand clientCmd=new StyleCommand(design,client);
        clientCmd.setStyleElement(null);
      }
 else {
        PropertyCommand cmd=new PropertyCommand(design,client);
        cmd.setProperty(ref.propName,null);
      }
    }
  }
}