Program: 126031
Project: 126031
Buggy source:
public static List<ContextReferenceBean> checkContextFromProcess(IProxyRepositoryFactory factory,DeleteActionCache deleteActionCache,RepositoryNode currentJobNode){
  IRepositoryViewObject object=currentJobNode.getObject();
  Item nodeItem=null;
  if (object != null && object.getProperty() != null) {
    nodeItem=object.getProperty().getItem();
  }
  boolean contextIsUsed=false;
  if (nodeItem != null && nodeItem instanceof ContextItem) {
    contextIsUsed=true;
  }
  List<ContextReferenceBean> list=new ArrayList<ContextReferenceBean>();
  if (deleteActionCache == null) {
    deleteActionCache=DeleteActionCache.getInstance();
    deleteActionCache.createRecords();
  }
  if (object != null && contextIsUsed) {
    Property property=object.getProperty();
    if (property != null) {
      String label=property.getLabel();
      String version=property.getVersion();
      Item item=property.getItem();
      if (!(item instanceof ContextItem)) {
        return list;
      }
      Set<Project> refParentProjects=new HashSet<Project>();
      try {
        refParentProjects.add(ProjectManager.getInstance().getCurrentProject());
        refParentProjects.addAll(ProjectManager.getInstance().getReferencedProjects());
        for (        Project refP : refParentProjects) {
          List<IRepositoryViewObject> objList=new ArrayList<IRepositoryViewObject>();
          List<IRepositoryViewObject> allJobVersions=new ArrayList<IRepositoryViewObject>();
          ERepositoryObjectType jobType=ERepositoryObjectType.PROCESS;
          if (jobType != null) {
            List<IRepositoryViewObject> processes=factory.getAll(refP,jobType);
            if (processes != null && processes.size() > 0) {
              for (              IRepositoryViewObject process : processes) {
                allJobVersions.addAll(factory.getAllVersion(process.getId()));
              }
            }
          }
          ERepositoryObjectType jobletType=ERepositoryObjectType.JOBLET;
          if (jobletType != null) {
            List<IRepositoryViewObject> jobletes=factory.getAll(refP,jobletType);
            allJobVersions.addAll(jobletes);
          }
          deleteActionCache.setProcessList(allJobVersions);
          objList.addAll(allJobVersions);
          List<IRepositoryViewObject> connectionc=factory.getAll(refP,ERepositoryObjectType.METADATA_CONNECTIONS);
          objList.addAll(connectionc);
          List<IRepositoryViewObject> edifact=factory.getAll(refP,ERepositoryObjectType.METADATA_EDIFACT);
          objList.addAll(edifact);
          List<IRepositoryViewObject> brms=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_BRMS);
          objList.addAll(brms);
          List<IRepositoryViewObject> delis=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_DELIMITED);
          objList.addAll(delis);
          List<IRepositoryViewObject> ebcdic=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_EBCDIC);
          objList.addAll(ebcdic);
          List<IRepositoryViewObject> excel=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_EXCEL);
          objList.addAll(excel);
          List<IRepositoryViewObject> ftp=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_FTP);
          objList.addAll(ftp);
          List<IRepositoryViewObject> hl7=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_HL7);
          objList.addAll(hl7);
          List<IRepositoryViewObject> ldif=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_LDIF);
          objList.addAll(ldif);
          List<IRepositoryViewObject> positional=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_POSITIONAL);
          objList.addAll(positional);
          List<IRepositoryViewObject> regexp=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_REGEXP);
          objList.addAll(regexp);
          List<IRepositoryViewObject> xmls=factory.getAll(refP,ERepositoryObjectType.METADATA_FILE_XML);
          objList.addAll(xmls);
          List<IRepositoryViewObject> mdms=factory.getAll(refP,ERepositoryObjectType.METADATA_MDMCONNECTION);
          objList.addAll(mdms);
          List<IRepositoryViewObject> wsdl=factory.getAll(refP,ERepositoryObjectType.METADATA_WSDL_SCHEMA);
          objList.addAll(wsdl);
          List<IRepositoryViewObject> saleForces=factory.getAll(refP,ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
          objList.addAll(saleForces);
          for (          IRepositoryViewObject process : objList) {
            Property property2=process.getProperty();
            boolean isDelete=factory.getStatus(process) == ERepositoryStatus.DELETED;
            boolean isJob=true;
            Item item2=property2.getItem();
            if (item == item2) {
              continue;
            }
            List<IContextParameter> openedContextParameterList=null;
            List<ContextParameterType> closedContextParameterList=null;
            String contextID=null;
            List<IProcess2> openedProcesses=RepositoryManagerHelper.getOpenedProcess();
            boolean isOpenedProcess=false;
            if (openedProcesses != null && openedProcesses.size() > 0) {
              for (              IProcess2 tempPro : openedProcesses) {
                if (process.getId().equals(tempPro.getId())) {
                  isOpenedProcess=true;
                  List<IContext> contextList=tempPro.getContextManager().getListContext();
                  if (contextList != null && !contextList.isEmpty()) {
                    openedContextParameterList=contextList.get(0).getContextParameterList();
                  }
                  break;
                }
              }
            }
            IDesignerCoreService service=(IDesignerCoreService)GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
            if (!isOpenedProcess) {
              if (item2 instanceof ConnectionItem) {
                contextID=((ConnectionItem)item2).getConnection().getContextId();
              }
 else {
                List<?> contextList=null;
                if (item2 instanceof ProcessItem) {
                  contextList=((ProcessItem)item2).getProcess().getContext();
                }
 else                 if (item2 instanceof JobletProcessItem) {
                  contextList=((JobletProcessItem)item2).getJobletProcess().getContext();
                }
                if (contextList != null && !contextList.isEmpty()) {
                  Object obj=contextList.get(0);
                  if (obj instanceof ContextType) {
                    closedContextParameterList=((ContextType)obj).getContextParameter();
                  }
                }
              }
            }
            List<?> contextParameterList=null;
            if (openedContextParameterList != null) {
              contextParameterList=openedContextParameterList;
            }
 else             if (closedContextParameterList != null) {
              contextParameterList=closedContextParameterList;
            }
            if (contextParameterList != null && contextParameterList.size() > 0) {
              for (int i=0; i < contextParameterList.size(); i++) {
                String sourceId=null;
                Object objContextParameter=contextParameterList.get(i);
                if (objContextParameter instanceof IContextParameter) {
                  IContextParameter contextParameter=(IContextParameter)objContextParameter;
                  sourceId=contextParameter.getSource();
                }
 else                 if (objContextParameter instanceof ContextParameterType) {
                  ContextParameterType contextParameter=(ContextParameterType)objContextParameter;
                  sourceId=contextParameter.getRepositoryContextId();
                }
                String contextId=item.getProperty().getId();
                if (contextId != null && contextId.equals(sourceId)) {
                  String processName=process.getLabel();
                  String processVersion=process.getVersion();
                  if (!RepositoryReferenceBeanUtils.hasReferenceBean(list,processName,processVersion)) {
                    String path=item2.getState().getPath();
                    String type=process.getRepositoryObjectType().getType();
                    ContextReferenceBean bean=new ContextReferenceBean(property2.getLabel(),type,property2.getVersion(),path,refP.getLabel());
                    bean.setJobFlag(isJob,isDelete);
                    list.add(bean);
                  }
                }
              }
            }
 else             if (contextID != null) {
              if (contextID.equals(item.getProperty().getId())) {
                String path=item2.getState().getPath();
                String type=process.getRepositoryObjectType().getType();
                ContextReferenceBean bean=new ContextReferenceBean(property2.getLabel(),type,property2.getVersion(),path,refP.getLabel());
                bean.setJobFlag(isJob,isDelete);
                list.add(bean);
                break;
              }
            }
          }
          for (          IProcess2 openedProcess : deleteActionCache.getOpenedProcessList()) {
            List<IContext> contextList=openedProcess.getContextManager().getListContext();
            for (            IContext context : contextList) {
              if (context.getContextParameterList().size() <= 0) {
                continue;
              }
              String source=context.getContextParameterList().get(0).getSource();
              if (source.equals(item.getProperty().getId())) {
                boolean isDelete=factory.getStatus(openedProcess) == ERepositoryStatus.DELETED;
                boolean isJob=true;
                Property property2=openedProcess.getProperty();
                Item item2=property2.getItem();
                String path=item2.getState().getPath();
                String processName=openedProcess.getLabel();
                String processVersion=openedProcess.getVersion();
                if (!RepositoryReferenceBeanUtils.hasReferenceBean(list,processName,processVersion)) {
                  ContextReferenceBean bean=new ContextReferenceBean(property2.getLabel(),openedProcess.getRepositoryObjectType().getType(),property2.getVersion(),path,refP.getLabel());
                  bean.setJobFlag(isJob,isDelete);
                  list.add(bean);
                  break;
                }
              }
            }
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
    }
  }
  return list;
}

Fixed version (ground truth):
public static List<ContextReferenceBean> checkContextFromProcess(IProxyRepositoryFactory factory,DeleteActionCache deleteActionCache,RepositoryNode currentJobNode){
  IRepositoryViewObject object=currentJobNode.getObject();
  Item nodeItem=null;
  if (object != null && object.getProperty() != null) {
    nodeItem=object.getProperty().getItem();
  }
  boolean contextIsUsed=false;
  if (nodeItem != null && nodeItem instanceof ContextItem) {
    contextIsUsed=true;
  }
  List<ContextReferenceBean> list=new ArrayList<ContextReferenceBean>();
  if (deleteActionCache == null) {
    deleteActionCache=DeleteActionCache.getInstance();
    deleteActionCache.createRecords();
  }
  if (object != null && contextIsUsed) {
    Property property=object.getProperty();
    if (property != null) {
      String label=property.getLabel();
      String version=property.getVersion();
      Item item=property.getItem();
      if (!(item instanceof ContextItem)) {
        return list;
      }
      Set<Project> refParentProjects=new HashSet<Project>();
      try {
        refParentProjects.add(ProjectManager.getInstance().getCurrentProject());
        refParentProjects.addAll(ProjectManager.getInstance().getReferencedProjects());
        for (        Project refP : refParentProjects) {
          List<IRepositoryViewObject> objList=new ArrayList<IRepositoryViewObject>();
          List<IRepositoryViewObject> allJobVersions=new ArrayList<IRepositoryViewObject>();
          ERepositoryObjectType jobType=ERepositoryObjectType.PROCESS;
          if (jobType != null) {
            List<IRepositoryViewObject> processes=factory.getAll(refP,jobType);
            if (processes != null && processes.size() > 0) {
              for (              IRepositoryViewObject process : processes) {
                allJobVersions.addAll(factory.getAllVersion(process.getId()));
              }
            }
          }
          ERepositoryObjectType jobletType=ERepositoryObjectType.JOBLET;
          if (jobletType != null) {
            List<IRepositoryViewObject> jobletes=factory.getAll(refP,jobletType);
            allJobVersions.addAll(jobletes);
          }
          deleteActionCache.setProcessList(allJobVersions);
          objList.addAll(allJobVersions);
          List<IRepositoryViewObject> metaDatas=factory.getAll(refP,ERepositoryObjectType.METADATA);
          objList.addAll(metaDatas);
          for (          IRepositoryViewObject process : objList) {
            Property property2=process.getProperty();
            boolean isDelete=factory.getStatus(process) == ERepositoryStatus.DELETED;
            boolean isJob=true;
            Item item2=property2.getItem();
            if (item == item2) {
              continue;
            }
            List<IContextParameter> openedContextParameterList=null;
            List<ContextParameterType> closedContextParameterList=null;
            String contextID=null;
            List<IProcess2> openedProcesses=RepositoryManagerHelper.getOpenedProcess();
            boolean isOpenedProcess=false;
            if (openedProcesses != null && openedProcesses.size() > 0) {
              for (              IProcess2 tempPro : openedProcesses) {
                if (process.getId().equals(tempPro.getId())) {
                  isOpenedProcess=true;
                  List<IContext> contextList=tempPro.getContextManager().getListContext();
                  if (contextList != null && !contextList.isEmpty()) {
                    openedContextParameterList=contextList.get(0).getContextParameterList();
                  }
                  break;
                }
              }
            }
            IDesignerCoreService service=(IDesignerCoreService)GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
            if (!isOpenedProcess) {
              if (item2 instanceof ConnectionItem) {
                contextID=((ConnectionItem)item2).getConnection().getContextId();
              }
 else {
                List<?> contextList=null;
                if (item2 instanceof ProcessItem) {
                  contextList=((ProcessItem)item2).getProcess().getContext();
                }
 else                 if (item2 instanceof JobletProcessItem) {
                  contextList=((JobletProcessItem)item2).getJobletProcess().getContext();
                }
                if (contextList != null && !contextList.isEmpty()) {
                  Object obj=contextList.get(0);
                  if (obj instanceof ContextType) {
                    closedContextParameterList=((ContextType)obj).getContextParameter();
                  }
                }
              }
            }
            List<?> contextParameterList=null;
            if (openedContextParameterList != null) {
              contextParameterList=openedContextParameterList;
            }
 else             if (closedContextParameterList != null) {
              contextParameterList=closedContextParameterList;
            }
            if (contextParameterList != null && contextParameterList.size() > 0) {
              for (int i=0; i < contextParameterList.size(); i++) {
                String sourceId=null;
                Object objContextParameter=contextParameterList.get(i);
                if (objContextParameter instanceof IContextParameter) {
                  IContextParameter contextParameter=(IContextParameter)objContextParameter;
                  sourceId=contextParameter.getSource();
                }
 else                 if (objContextParameter instanceof ContextParameterType) {
                  ContextParameterType contextParameter=(ContextParameterType)objContextParameter;
                  sourceId=contextParameter.getRepositoryContextId();
                }
                String contextId=item.getProperty().getId();
                if (contextId != null && contextId.equals(sourceId)) {
                  String processName=process.getLabel();
                  String processVersion=process.getVersion();
                  if (!RepositoryReferenceBeanUtils.hasReferenceBean(list,processName,processVersion)) {
                    String path=item2.getState().getPath();
                    String type=process.getRepositoryObjectType().getType();
                    ContextReferenceBean bean=new ContextReferenceBean(property2.getLabel(),type,property2.getVersion(),path,refP.getLabel());
                    bean.setJobFlag(isJob,isDelete);
                    list.add(bean);
                  }
                }
              }
            }
 else             if (contextID != null) {
              if (contextID.equals(item.getProperty().getId())) {
                String path=item2.getState().getPath();
                String type=process.getRepositoryObjectType().getType();
                ContextReferenceBean bean=new ContextReferenceBean(property2.getLabel(),type,property2.getVersion(),path,refP.getLabel());
                bean.setJobFlag(isJob,isDelete);
                list.add(bean);
                break;
              }
            }
          }
          for (          IProcess2 openedProcess : deleteActionCache.getOpenedProcessList()) {
            List<IContext> contextList=openedProcess.getContextManager().getListContext();
            for (            IContext context : contextList) {
              if (context.getContextParameterList().size() <= 0) {
                continue;
              }
              String source=context.getContextParameterList().get(0).getSource();
              if (source.equals(item.getProperty().getId())) {
                boolean isDelete=factory.getStatus(openedProcess) == ERepositoryStatus.DELETED;
                boolean isJob=true;
                Property property2=openedProcess.getProperty();
                Item item2=property2.getItem();
                String path=item2.getState().getPath();
                String processName=openedProcess.getLabel();
                String processVersion=openedProcess.getVersion();
                if (!RepositoryReferenceBeanUtils.hasReferenceBean(list,processName,processVersion)) {
                  ContextReferenceBean bean=new ContextReferenceBean(property2.getLabel(),openedProcess.getRepositoryObjectType().getType(),property2.getVersion(),path,refP.getLabel());
                  bean.setJobFlag(isJob,isDelete);
                  list.add(bean);
                  break;
                }
              }
            }
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
    }
  }
  return list;
}