Program: 119032
Project: 119032
Buggy source:
protected static List<IComponent> getRelatedComponents(final IComponentsFactory compFac,String keyword,boolean needCheckVisible){
  Set<IComponent> componentSet=null;
  IComponentsHandler componentsHandler=compFac.getComponentsHandler();
  String lowerCasedKeyword=null;
  if (keyword != null) {
    lowerCasedKeyword=keyword.toLowerCase().trim();
  }
  if (compFac != null && lowerCasedKeyword != null && 0 < lowerCasedKeyword.length()) {
    Map<String,Map<String,Set<IComponent>>> componentNameMap=compFac.getComponentNameMap();
    if (componentNameMap != null) {
      Map<String,Set<IComponent>> map=componentNameMap.get(lowerCasedKeyword);
      if (map != null) {
        Collection<Set<IComponent>> componentSets=map.values();
        Iterator<Set<IComponent>> componentSetIter=componentSets.iterator();
        List<IComponent> filteredComponent=new ArrayList<IComponent>();
        while (componentSetIter.hasNext()) {
          filteredComponent.addAll(componentSetIter.next());
        }
        if (componentsHandler != null) {
          filteredComponent=componentsHandler.filterComponents(filteredComponent);
        }
        Iterator<IComponent> componentIter=filteredComponent.iterator();
        while (componentIter.hasNext()) {
          if (!ComponentUtilities.isComponentVisible(componentIter.next())) {
            componentIter.remove();
          }
        }
        componentSet=new HashSet<IComponent>(filteredComponent);
      }
    }
    if ((componentSet == null || componentSet.isEmpty()) && componentNameMap != null) {
      componentSet=new HashSet<IComponent>();
      addComponentsByNameFilter(compFac,componentSet,lowerCasedKeyword);
      boolean shouldSearchFromHelpAPI=PaletteSettingsPreferencePage.isPaletteSearchFromHelp();
      if (shouldSearchFromHelpAPI) {
        String helpKeyword=keyword;
        if (helpKeyword != null) {
          helpKeyword=helpKeyword.trim();
        }
        Set<String> componentNames=getRelatedComponentNamesFromHelp(helpKeyword);
        if (componentNames != null && 0 < componentNames.size()) {
          int limit=PaletteSettingsPreferencePage.getPaletteSearchResultLimitFromHelp();
          int i=0;
          Iterator<String> nameIter=componentNames.iterator();
          while (nameIter.hasNext()) {
            if (limit <= i) {
              break;
            }
            String componentName=nameIter.next();
            Map<String,Set<IComponent>> map=componentNameMap.get(componentName.toLowerCase());
            if (map == null) {
              continue;
            }
            Set<IComponent> findedComponents=map.get(componentName);
            if (findedComponents != null && !findedComponents.isEmpty()) {
              for (              IComponent iComponent : findedComponents) {
                if (limit <= i) {
                  break;
                }
                if (ComponentUtilities.isComponentVisible(iComponent) && !iComponent.isTechnical() && filterComponent(iComponent,componentsHandler)) {
                  componentSet.add(iComponent);
                  i++;
                }
              }
            }
          }
        }
      }
    }
  }
 else   if (compFac != null) {
    componentSet=compFac.getComponents();
  }
  List<IComponent> relatedComponents=null;
  if (componentSet == null || componentSet.isEmpty()) {
    relatedComponents=new LinkedList<IComponent>();
  }
 else {
    relatedComponents=new LinkedList<IComponent>(componentSet);
  }
  if (compFac != null && componentsHandler != null && !relatedComponents.isEmpty()) {
    relatedComponents=componentsHandler.filterComponents(relatedComponents);
  }
  if (needCheckVisible && relatedComponents != null && !relatedComponents.isEmpty()) {
    Iterator<IComponent> iter=relatedComponents.iterator();
    while (iter.hasNext()) {
      IComponent component=iter.next();
      if (component == null || !ComponentUtilities.isComponentVisible(component) || component.isTechnical()) {
        iter.remove();
      }
    }
  }
  return relatedComponents;
}

Fixed version (ground truth):
protected static List<IComponent> getRelatedComponents(final IComponentsFactory compFac,String keyword,boolean needCheckVisible){
  Set<IComponent> componentSet=null;
  IComponentsHandler componentsHandler=compFac.getComponentsHandler();
  String lowerCasedKeyword=null;
  if (keyword != null) {
    lowerCasedKeyword=keyword.toLowerCase().trim();
  }
  if (compFac != null && lowerCasedKeyword != null && 0 < lowerCasedKeyword.length()) {
    Map<String,Map<String,Set<IComponent>>> componentNameMap=compFac.getComponentNameMap();
    if (componentNameMap != null) {
      Map<String,Set<IComponent>> map=componentNameMap.get(lowerCasedKeyword);
      if (map != null) {
        Collection<Set<IComponent>> componentSets=map.values();
        Iterator<Set<IComponent>> componentSetIter=componentSets.iterator();
        List<IComponent> filteredComponent=new ArrayList<IComponent>();
        while (componentSetIter.hasNext()) {
          filteredComponent.addAll(componentSetIter.next());
        }
        if (componentsHandler != null) {
          filteredComponent=componentsHandler.filterComponents(filteredComponent);
        }
        Iterator<IComponent> componentIter=filteredComponent.iterator();
        while (componentIter.hasNext()) {
          IComponent iComponent=componentIter.next();
          if (iComponent == null || !ComponentUtilities.isComponentVisible(iComponent) || iComponent.isTechnical()) {
            componentIter.remove();
          }
        }
        componentSet=new HashSet<IComponent>(filteredComponent);
      }
    }
    if ((componentSet == null || componentSet.isEmpty()) && componentNameMap != null) {
      componentSet=new HashSet<IComponent>();
      addComponentsByNameFilter(compFac,componentSet,lowerCasedKeyword);
      boolean shouldSearchFromHelpAPI=PaletteSettingsPreferencePage.isPaletteSearchFromHelp();
      if (shouldSearchFromHelpAPI) {
        String helpKeyword=keyword;
        if (helpKeyword != null) {
          helpKeyword=helpKeyword.trim();
        }
        Set<String> componentNames=getRelatedComponentNamesFromHelp(helpKeyword);
        if (componentNames != null && 0 < componentNames.size()) {
          int limit=PaletteSettingsPreferencePage.getPaletteSearchResultLimitFromHelp();
          int i=0;
          Iterator<String> nameIter=componentNames.iterator();
          while (nameIter.hasNext()) {
            if (limit <= i) {
              break;
            }
            String componentName=nameIter.next();
            Map<String,Set<IComponent>> map=componentNameMap.get(componentName.toLowerCase());
            if (map == null) {
              continue;
            }
            Set<IComponent> findedComponents=map.get(componentName);
            if (findedComponents != null && !findedComponents.isEmpty()) {
              for (              IComponent iComponent : findedComponents) {
                if (limit <= i) {
                  break;
                }
                if (ComponentUtilities.isComponentVisible(iComponent) && !iComponent.isTechnical() && filterComponent(iComponent,componentsHandler)) {
                  componentSet.add(iComponent);
                  i++;
                }
              }
            }
          }
        }
      }
    }
  }
 else   if (compFac != null) {
    componentSet=compFac.getComponents();
  }
  List<IComponent> relatedComponents=null;
  if (componentSet == null || componentSet.isEmpty()) {
    relatedComponents=new LinkedList<IComponent>();
  }
 else {
    relatedComponents=new LinkedList<IComponent>(componentSet);
  }
  if (compFac != null && componentsHandler != null && !relatedComponents.isEmpty()) {
    relatedComponents=componentsHandler.filterComponents(relatedComponents);
  }
  if (needCheckVisible && relatedComponents != null && !relatedComponents.isEmpty()) {
    Iterator<IComponent> iter=relatedComponents.iterator();
    while (iter.hasNext()) {
      IComponent component=iter.next();
      if (component == null || !ComponentUtilities.isComponentVisible(component) || component.isTechnical()) {
        iter.remove();
      }
    }
  }
  return relatedComponents;
}