Program: 125525
Project: 125525
Buggy source:
private static void addContextForHadoopElementParameters(final IProcess2 process,final ConnectionItem connItem,List<? extends IElementParameter> elementParameters,final EComponentCategory category,final boolean ignoreContextMode){
  IHadoopClusterService hadoopClusterService=null;
  if (GlobalServiceRegister.getDefault().isServiceRegistered(IHadoopClusterService.class)) {
    hadoopClusterService=(IHadoopClusterService)GlobalServiceRegister.getDefault().getService(IHadoopClusterService.class);
  }
  if (hadoopClusterService != null) {
    if (hadoopClusterService.isInContextMode(connItem)) {
      Connection connection=connItem.getConnection();
      Set<String> neededVars=retrieveContextVar(elementParameters,connection,category);
      if (neededVars != null && !neededVars.isEmpty()) {
        ContextItem contextItem=ContextUtils.getContextItemById2(connection.getContextId());
        ConnectionItem hadoopClusterItem=(ConnectionItem)hadoopClusterService.getHadoopClusterBySubitemId(connItem.getProperty().getId());
        Connection hadoopClusterConnection=hadoopClusterItem.getConnection();
        ContextItem hadoopClusterContextItem=ContextUtils.getContextItemById2(hadoopClusterConnection.getContextId());
        Set<String> hcNeededVars=retrieveContextVar(elementParameters,hadoopClusterConnection,category,true);
        List<ContextItem> contextItems=new ArrayList<>();
        if (contextItem != null || hadoopClusterContextItem != null) {
          Set<String> connAddedVars=null;
          Set<String> hcAddedVars=null;
          if (contextItem != null) {
            connAddedVars=checkAndAddContextVariables(contextItem,neededVars,process.getContextManager(),false);
            contextItems.add(contextItem);
          }
          if (hadoopClusterContextItem != null) {
            hcAddedVars=checkAndAddContextVariables(hadoopClusterContextItem,hcNeededVars,process.getContextManager(),false);
            contextItems.add(hadoopClusterContextItem);
          }
          boolean added=false;
          Map<String,Set<String>> addedVarsMap=new HashMap<>();
          Map<ContextItem,Set<String>> contextToVars=new HashMap<>();
          if (connAddedVars != null && !connAddedVars.isEmpty() && !isAddContextVar(contextItem,process.getContextManager(),neededVars)) {
            if (ignoreContextMode) {
              addContextVarForJob(process,contextItem,connAddedVars);
              added=true;
            }
 else {
              addedVarsMap.put(connItem.getProperty().getId(),connAddedVars);
              contextToVars.put(contextItem,connAddedVars);
            }
          }
          if (hcAddedVars != null && !hcAddedVars.isEmpty() && !isAddContextVar(hadoopClusterContextItem,process.getContextManager(),hcNeededVars)) {
            if (ignoreContextMode) {
              addContextVarForJob(process,hadoopClusterContextItem,hcAddedVars);
              added=true;
            }
 else {
              addedVarsMap.put(hadoopClusterItem.getProperty().getId(),hcAddedVars);
              contextToVars.put(hadoopClusterContextItem,hcAddedVars);
            }
          }
          if (addedVarsMap.size() > 0) {
            if (showContextDialogForHadoop(process,contextItems,process.getContextManager(),addedVarsMap,contextToVars)) {
              added=true;
            }
          }
          if (added) {
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
              IDesignerCoreService service=(IDesignerCoreService)GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
              service.switchToCurContextsView();
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
private static void addContextForHadoopElementParameters(final IProcess2 process,final ConnectionItem connItem,List<? extends IElementParameter> elementParameters,final EComponentCategory category,final boolean ignoreContextMode){
  IHadoopClusterService hadoopClusterService=null;
  if (GlobalServiceRegister.getDefault().isServiceRegistered(IHadoopClusterService.class)) {
    hadoopClusterService=(IHadoopClusterService)GlobalServiceRegister.getDefault().getService(IHadoopClusterService.class);
  }
  if (hadoopClusterService != null) {
    Connection connection=connItem.getConnection();
    if (hadoopClusterService.isInContextMode(connection)) {
      Set<String> neededVars=retrieveContextVar(elementParameters,connection,category);
      if (neededVars != null && !neededVars.isEmpty()) {
        ContextItem contextItem=ContextUtils.getContextItemById2(connection.getContextId());
        ConnectionItem hadoopClusterItem=(ConnectionItem)hadoopClusterService.getHadoopClusterBySubitemId(connItem.getProperty().getId());
        Connection hadoopClusterConnection=hadoopClusterItem.getConnection();
        ContextItem hadoopClusterContextItem=ContextUtils.getContextItemById2(hadoopClusterConnection.getContextId());
        Set<String> hcNeededVars=retrieveContextVar(elementParameters,hadoopClusterConnection,category,true);
        List<ContextItem> contextItems=new ArrayList<>();
        if (contextItem != null || hadoopClusterContextItem != null) {
          Set<String> connAddedVars=null;
          Set<String> hcAddedVars=null;
          if (contextItem != null) {
            connAddedVars=checkAndAddContextVariables(contextItem,neededVars,process.getContextManager(),false);
            contextItems.add(contextItem);
          }
          if (hadoopClusterContextItem != null) {
            hcAddedVars=checkAndAddContextVariables(hadoopClusterContextItem,hcNeededVars,process.getContextManager(),false);
            contextItems.add(hadoopClusterContextItem);
          }
          boolean added=false;
          Map<String,Set<String>> addedVarsMap=new HashMap<>();
          Map<ContextItem,Set<String>> contextToVars=new HashMap<>();
          if (connAddedVars != null && !connAddedVars.isEmpty() && !isAddContextVar(contextItem,process.getContextManager(),neededVars)) {
            if (ignoreContextMode) {
              addContextVarForJob(process,contextItem,connAddedVars);
              added=true;
            }
 else {
              addedVarsMap.put(connItem.getProperty().getId(),connAddedVars);
              contextToVars.put(contextItem,connAddedVars);
            }
          }
          if (hcAddedVars != null && !hcAddedVars.isEmpty() && !isAddContextVar(hadoopClusterContextItem,process.getContextManager(),hcNeededVars)) {
            if (ignoreContextMode) {
              addContextVarForJob(process,hadoopClusterContextItem,hcAddedVars);
              added=true;
            }
 else {
              addedVarsMap.put(hadoopClusterItem.getProperty().getId(),hcAddedVars);
              contextToVars.put(hadoopClusterContextItem,hcAddedVars);
            }
          }
          if (addedVarsMap.size() > 0) {
            if (showContextDialogForHadoop(process,contextItems,process.getContextManager(),addedVarsMap,contextToVars)) {
              added=true;
            }
          }
          if (added) {
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
              IDesignerCoreService service=(IDesignerCoreService)GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
              service.switchToCurContextsView();
            }
          }
        }
      }
    }
  }
}