Program: 137519
Project: 137519
Buggy source:
@Override public void mouseDown(MouseEvent e){
  DataManager dm=getAnalysis().getContext().getConnection();
  if (dm == null) {
    masterPage.doSave(null);
  }
  if (dm != null && dm instanceof Connection) {
    Connection dp=(Connection)dm;
    if (ConnectionUtils.isMdmConnection(dp)) {
      MessageUI.openWarning(DefaultMessagesImpl.getString("String_Node_Str"));
      return;
    }
  }
  IFolder udiProject=ResourceManager.getUDIFolder();
  CheckedTreeSelectionDialog dialog=UDIUtils.createUdiCheckedTreeSelectionDialog(udiProject,meIndicator);
  if (dialog.open() == Window.OK) {
    List<IFile> allSelectedFiles=new ArrayList<IFile>();
    Set<String> allSelectedIndNames=new HashSet<String>();
    for (    Object obj : dialog.getResult()) {
      if (obj instanceof IFile) {
        allSelectedFiles.add((IFile)obj);
        IndicatorDefinition udid=IndicatorResourceFileHelper.getInstance().findIndDefinition((IFile)obj);
        if (udid != null) {
          allSelectedIndNames.add(udid.getName());
        }
      }
    }
    Set<String> oldSelectedIndNames=new HashSet<String>();
    for (    IndicatorUnit indicatorUnit : meIndicator.getIndicatorUnits()) {
      Indicator indicator=indicatorUnit.getIndicator();
      if (indicator instanceof UserDefIndicator) {
        if (allSelectedIndNames.contains(indicator.getName())) {
          oldSelectedIndNames.add(indicator.getName());
        }
 else {
          meIndicator.removeIndicatorUnit(indicatorUnit);
          if (!isDirty()) {
            setDirty(true);
          }
        }
      }
    }
    treeItem.removeAll();
    for (    IFile file : allSelectedFiles) {
      IndicatorDefinition udid=IndicatorResourceFileHelper.getInstance().findIndDefinition(file);
      if (udid != null && oldSelectedIndNames.contains(udid.getName())) {
        continue;
      }
      IndicatorUnit[] addIndicatorUnits=null;
      try {
        addIndicatorUnits=UDIUtils.createIndicatorUnit(file,meIndicator,getAnalysis());
      }
 catch (      Throwable e1) {
        log.warn(e1,e1);
      }
      if (addIndicatorUnits != null && addIndicatorUnits.length > 0) {
        for (        IndicatorUnit unit : addIndicatorUnits) {
          createOneUnit(treeItem,unit);
        }
        if (!isDirty()) {
          setDirty(true);
        }
      }
    }
    treeItem.setExpanded(true);
    masterPage.refreshTheTree(masterPage.getCurrentModelElementIndicators());
  }
}

Fixed version (ground truth):
@Override public void mouseDown(MouseEvent e){
  DataManager dm=getAnalysis().getContext().getConnection();
  if (dm == null) {
    masterPage.doSave(null);
  }
  if (dm != null && dm instanceof Connection) {
    Connection dp=(Connection)dm;
    if (ConnectionUtils.isMdmConnection(dp)) {
      MessageUI.openWarning(DefaultMessagesImpl.getString("String_Node_Str"));
      return;
    }
  }
  IFolder udiProject=ResourceManager.getUDIFolder();
  CheckedTreeSelectionDialog dialog=UDIUtils.createUdiCheckedTreeSelectionDialog(udiProject,meIndicator);
  if (dialog.open() == Window.OK) {
    List<IFile> allSelectedFiles=new ArrayList<IFile>();
    Set<String> allSelectedIndNames=new HashSet<String>();
    for (    Object obj : dialog.getResult()) {
      if (obj instanceof IFile) {
        allSelectedFiles.add((IFile)obj);
        IndicatorDefinition udid=IndicatorResourceFileHelper.getInstance().findIndDefinition((IFile)obj);
        if (udid != null) {
          allSelectedIndNames.add(udid.getName());
        }
      }
    }
    Set<String> oldSelectedIndNames=new HashSet<String>();
    for (    IndicatorUnit indicatorUnit : meIndicator.getIndicatorUnits()) {
      Indicator indicator=indicatorUnit.getIndicator();
      if (indicator instanceof UserDefIndicator) {
        if (allSelectedIndNames.contains(indicator.getName())) {
          oldSelectedIndNames.add(indicator.getName());
        }
 else {
          deleteIndicatorItems(meIndicator,indicatorUnit);
          if (!isDirty()) {
            setDirty(true);
          }
        }
      }
    }
    treeItem.removeAll();
    for (    IFile file : allSelectedFiles) {
      IndicatorDefinition udid=IndicatorResourceFileHelper.getInstance().findIndDefinition(file);
      if (udid != null && oldSelectedIndNames.contains(udid.getName())) {
        continue;
      }
      IndicatorUnit[] addIndicatorUnits=null;
      try {
        addIndicatorUnits=UDIUtils.createIndicatorUnit(file,meIndicator,getAnalysis());
      }
 catch (      Throwable e1) {
        log.warn(e1,e1);
      }
      if (addIndicatorUnits != null && addIndicatorUnits.length > 0) {
        for (        IndicatorUnit unit : addIndicatorUnits) {
          createOneUnit(treeItem,unit);
        }
        if (!isDirty()) {
          setDirty(true);
        }
      }
    }
    treeItem.setExpanded(true);
    masterPage.refreshTheTree(masterPage.getCurrentModelElementIndicators());
  }
}