Program: 59043
Project: 59043
Buggy source:
/** 
 * <p> Merge an external selection delta into the local selection, and return a possibly converted selection </p> <p> This method takes into account data mapping, when mapping types are set </p> <p> When an element in the selectionDelta is not contained in the selection manager it is added and then moved to the appropriate type </p> <p> If a virtual array is set, the virtual array is also modified if necessary. This is the case when new element which are not contained in the virtual array are added or when elements are removed. </p>
 * @param selectionDelta the selection delta
 * @return a ISelectionDelta that contains the internal ID of the manager asits primary ID
 */
public ISelectionDelta setDelta(ISelectionDelta selectionDelta){
  if (externalToInternalMapping != null) {
    ISelectionDelta externalSelectionDelta=selectionDelta;
    selectionDelta=new SelectionDelta(internalIDType);
    for (    SelectionItem item : externalSelectionDelta) {
      Integer iInternalID=GeneralManager.get().getGenomeIdManager().getID(externalToInternalMapping,item.getSelectionID());
      if (iInternalID == null || iInternalID == -1) {
        GeneralManager.get().getLogger().log(Level.WARNING,"String_Node_Str" + item.getSelectionID());
        continue;
      }
      if (!checkStatus(iInternalID)) {
        if (item.getSelectionType() != ESelectionType.REMOVE) {
          initialAdd(iInternalID);
          if (virtualArray != null)           virtualArray.add(iInternalID);
        }
      }
 else {
        if (item.getSelectionType() == ESelectionType.REMOVE && virtualArray != null)         virtualArray.removeByElement(iInternalID);
      }
      if (item.getInternalID() != -1 && item.getInternalID() != iInternalID)       selectionDelta.addSelection(iInternalID,item.getSelectionType(),item.getInternalID());
 else       selectionDelta.addSelection(iInternalID,item.getSelectionType(),item.getSelectionID());
    }
  }
  bIsDeltaWritingEnabled=false;
  for (  SelectionItem selection : selectionDelta) {
    ESelectionType type=selection.getSelectionType();
    if (!alSelectionTypes.contains(type))     continue;
    addToType(type,selection.getSelectionID());
  }
  bIsDeltaWritingEnabled=true;
  return selectionDelta;
}

Fixed version (ground truth):
/** 
 * <p> Merge an external selection delta into the local selection, and return a possibly converted selection </p> <p> This method takes into account data mapping, when mapping types are set </p> <p> When an element in the selectionDelta is not contained in the selection manager it is added and then moved to the appropriate type </p> <p> If a virtual array is set, the virtual array is also modified if necessary. This is the case when new element which are not contained in the virtual array are added or when elements are removed. </p>
 * @param selectionDelta the selection delta
 * @return a ISelectionDelta that contains the internal ID of the manager asits primary ID
 */
public ISelectionDelta setDelta(ISelectionDelta selectionDelta){
  if (externalToInternalMapping != null) {
    ISelectionDelta externalSelectionDelta=selectionDelta;
    selectionDelta=new SelectionDelta(internalIDType);
    for (    SelectionItem item : externalSelectionDelta) {
      Integer iInternalID=GeneralManager.get().getGenomeIdManager().getID(externalToInternalMapping,item.getSelectionID());
      if (iInternalID == null || iInternalID == -1) {
        GeneralManager.get().getLogger().log(Level.WARNING,"String_Node_Str" + item.getSelectionID());
        continue;
      }
      if (!checkStatus(iInternalID)) {
        if (item.getSelectionType() == ESelectionType.ADD) {
          initialAdd(iInternalID);
          if (virtualArray != null)           virtualArray.add(iInternalID);
        }
      }
 else {
        if (item.getSelectionType() == ESelectionType.REMOVE && virtualArray != null)         virtualArray.removeByElement(iInternalID);
      }
      if (item.getInternalID() != -1 && item.getInternalID() != iInternalID)       selectionDelta.addSelection(iInternalID,item.getSelectionType(),item.getInternalID());
 else       selectionDelta.addSelection(iInternalID,item.getSelectionType(),item.getSelectionID());
    }
  }
  bIsDeltaWritingEnabled=false;
  for (  SelectionItem selection : selectionDelta) {
    ESelectionType type=selection.getSelectionType();
    if (!alSelectionTypes.contains(type))     continue;
    addToType(type,selection.getSelectionID());
  }
  bIsDeltaWritingEnabled=true;
  return selectionDelta;
}