Program: 125761
Project: 125761
Buggy source:
/** 
 * check if there exist variables which need to add into the ctxManager.
 * @param contexts
 * @param defaultContextName
 * @param contextItemId
 * @param neededVars
 * @param ctxManager
 * @param added add the variable or not
 * @return
 */
public static Set<String> checkAndAddContextVariables(final List<ContextType> contexts,final String defaultContextName,final String contextItemId,final Set<String> neededVars,final IContextManager ctxManager,boolean added){
  Set<String> addedVars=new HashSet<String>();
  for (  IContext context : ctxManager.getListContext()) {
    ContextType type=ContextUtils.getContextTypeByName(contexts,context.getName(),defaultContextName);
    if (type != null) {
      for (      String var : neededVars) {
        if (context.getContextParameter(var) != null) {
          continue;
        }
        ContextParameterType param=ContextUtils.getContextParameterTypeByName(type,var);
        if (param != null) {
          if (added) {
            JobContextParameter contextParam=new JobContextParameter();
            ContextUtils.updateParameter(param,contextParam);
            if (contextItemId != null) {
              contextParam.setSource(contextItemId);
            }
            contextParam.setContext(context);
            context.getContextParameterList().add(contextParam);
          }
          addedVars.add(var);
        }
      }
    }
  }
  return addedVars;
}

Fixed version (ground truth):
/** 
 * check if there exist variables which need to add into the ctxManager.
 * @param contexts
 * @param defaultContextName
 * @param contextItemId
 * @param neededVars
 * @param ctxManager
 * @param added add the variable or not
 * @return
 */
public static Set<String> checkAndAddContextVariables(final List<ContextType> contexts,final String defaultContextName,final String contextItemId,final Set<String> neededVars,final IContextManager ctxManager,boolean added){
  Set<String> addedVars=new HashSet<String>();
  for (  IContext context : ctxManager.getListContext()) {
    ContextType type=ContextUtils.getContextTypeByName(contexts,context.getName(),defaultContextName);
    if (type != null) {
      for (      IContextParameter jobParam : context.getContextParameterList()) {
        if (contextItemId.equals(jobParam.getSource()) && ContextUtils.getContextParameterTypeByName(type,jobParam.getName()) == null) {
          jobParam.setSource(IContextParameter.BUILT_IN);
        }
      }
      for (      String var : neededVars) {
        if (context.getContextParameter(var) != null) {
          continue;
        }
        ContextParameterType param=ContextUtils.getContextParameterTypeByName(type,var);
        if (param != null) {
          if (added) {
            JobContextParameter contextParam=new JobContextParameter();
            ContextUtils.updateParameter(param,contextParam);
            if (contextItemId != null) {
              contextParam.setSource(contextItemId);
            }
            contextParam.setContext(context);
            context.getContextParameterList().add(contextParam);
          }
          addedVars.add(var);
        }
      }
    }
  }
  return addedVars;
}