Program: 129737
Project: 129737
Buggy source:
public void addOrUpdateItem(Item item,boolean fromMigration){
  if (!loaded) {
    loadRelations();
  }
  ProcessType processType=null;
  if (item instanceof ProcessItem) {
    processType=((ProcessItem)item).getProcess();
  }
  if (item instanceof JobletProcessItem) {
    processType=((JobletProcessItem)item).getJobletProcess();
  }
  if (processType != null) {
    boolean relationsModified=true;
    Relation relation=new Relation();
    relation.setId(item.getProperty().getId());
    relation.setType(getTypeFromItem(item));
    relation.setVersion(item.getProperty().getVersion());
    Set<Relation> oldProjectRelations=null;
    if (currentProjectItemsRelations.containsKey(relation)) {
      oldProjectRelations=new HashSet<Relation>(currentProjectItemsRelations.get(relation));
      currentProjectItemsRelations.get(relation).clear();
    }
    clearItemsRelations(item);
    Boolean builtIn=null;
    String currentValue=null;
    String relationType=null;
    for (    Object o : processType.getContext()) {
      ContextType context=(ContextType)o;
      for (      Object o2 : context.getContextParameter()) {
        ContextParameterType contextParam=(ContextParameterType)o2;
        if (!StringUtils.isEmpty(contextParam.getRepositoryContextId())) {
          addRelationShip(item,contextParam.getRepositoryContextId(),LATEST_VERSION,CONTEXT_RELATION);
        }
      }
    }
    if (processType.getParameters() != null) {
      if (processType.getParameters().getRoutinesParameter() != null) {
        for (        Object o : processType.getParameters().getRoutinesParameter()) {
          RoutinesParameterType itemInfor=(RoutinesParameterType)o;
          addRelationShip(item,itemInfor.getName(),LATEST_VERSION,ROUTINE_RELATION);
        }
      }
      for (      Object o : processType.getParameters().getElementParameter()) {
        if (o instanceof ElementParameterType) {
          ElementParameterType param=(ElementParameterType)o;
          if (param.getName().startsWith("String_Node_Str")) {
            relationType=SCHEMA_RELATION;
          }
 else           if (param.getName().startsWith("String_Node_Str")) {
            relationType=PROPERTY_RELATION;
          }
 else           if (param.getName().startsWith("String_Node_Str")) {
            relationType=VALIDATION_RULE_RELATION;
          }
 else {
            builtIn=null;
            currentValue=null;
          }
          if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")) {
            builtIn=true;
            if (param.getValue().equals("String_Node_Str")) {
              builtIn=false;
            }
          }
          if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")) {
            currentValue=param.getValue();
          }
          if (builtIn != null && currentValue != null) {
            if (!builtIn) {
              addRelationShip(item,currentValue,LATEST_VERSION,relationType);
            }
            builtIn=null;
            currentValue=null;
          }
        }
      }
    }
    List<String> jobletsComponentsList=new ArrayList<String>();
    IComponentsService compService=(IComponentsService)GlobalServiceRegister.getDefault().getService(IComponentsService.class);
    for (    IComponent component : compService.getComponentsFactory().getComponents()) {
      if (component.getComponentType() == EComponentType.JOBLET) {
        jobletsComponentsList.add(component.getName());
      }
    }
    builtIn=null;
    currentValue=null;
    for (    Object o : processType.getNode()) {
      if (o instanceof NodeType) {
        NodeType currentNode=(NodeType)o;
        for (        Object o2 : currentNode.getElementParameter()) {
          if (o2 instanceof ElementParameterType) {
            ElementParameterType param=(ElementParameterType)o2;
            if (param.getName().startsWith("String_Node_Str")) {
              relationType=QUERY_RELATION;
            }
 else             if (param.getName().startsWith("String_Node_Str") || param.getName().startsWith("String_Node_Str")) {
              relationType=SCHEMA_RELATION;
            }
 else             if (param.getName().startsWith("String_Node_Str")) {
              relationType=PROPERTY_RELATION;
            }
 else             if (param.getName().startsWith("String_Node_Str")) {
              relationType=VALIDATION_RULE_RELATION;
            }
 else {
              builtIn=null;
              currentValue=null;
            }
            if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")|| param.getName().endsWith("String_Node_Str")) {
              builtIn=true;
              if (param.getValue().equals("String_Node_Str")) {
                builtIn=false;
              }
            }
            if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")|| param.getName().endsWith("String_Node_Str")) {
              currentValue=param.getValue();
            }
            if (builtIn != null && currentValue != null) {
              if (!builtIn) {
                addRelationShip(item,currentValue,LATEST_VERSION,relationType);
              }
              builtIn=null;
              currentValue=null;
            }
            if (param.getName().equals("String_Node_Str")) {
              for (              Object o3 : param.getElementValue()) {
                if (o3 instanceof ElementValueType && "String_Node_Str".equals(((ElementValueType)o3).getElementRef())) {
                  addRelationShip(item,((ElementValueType)o3).getValue(),LATEST_VERSION,SQLPATTERN_RELATION);
                }
              }
            }
            if (param.getField().equals(EParameterFieldType.SURVIVOR_RELATION.getName())) {
              String relatedID=param.getValue();
              addRelationShip(item,relatedID,LATEST_VERSION,SURVIVOR_RELATION);
            }
          }
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
          IDesignerMapperService service=(IDesignerMapperService)GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
          AbstractExternalData nodeData=currentNode.getNodeData();
          List<String> schemaIds=service.getRepositorySchemaIds(nodeData);
          if (schemaIds.size() > 0) {
            for (            String schemaId : schemaIds) {
              addRelationShip(item,schemaId,LATEST_VERSION,SCHEMA_RELATION);
            }
          }
        }
        if (jobletsComponentsList.contains(currentNode.getComponentName())) {
          String version=LATEST_VERSION;
          for (          Object o2 : currentNode.getElementParameter()) {
            if (o2 instanceof ElementParameterType) {
              ElementParameterType param=(ElementParameterType)o2;
              if (param.getName().equals("String_Node_Str")) {
                version=param.getValue();
              }
            }
          }
          IComponent cc=compService.getComponentsFactory().get(currentNode.getComponentName());
          IJobletProviderService service=null;
          if (PluginChecker.isJobLetPluginLoaded()) {
            service=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
          }
          Property property=service.getJobletComponentItem(cc);
          if (property != null)           addRelationShip(item,property.getId(),version,JOBLET_RELATION);
        }
        if ("String_Node_Str".equals(currentNode.getComponentName())) {
          String jobVersion=LATEST_VERSION;
          Set<String> jobIdSet=new HashSet<String>();
          for (          Object o2 : currentNode.getElementParameter()) {
            if (o2 instanceof ElementParameterType) {
              ElementParameterType param=(ElementParameterType)o2;
              if (param.getName().equals("String_Node_Str") || param.getName().equals("String_Node_Str")) {
                String jobIds=param.getValue();
                String[] jobsArr=jobIds.split(RelationshipItemBuilder.COMMA);
                for (                String jobId : jobsArr) {
                  if (StringUtils.isNotEmpty(jobId)) {
                    jobIdSet.add(jobId);
                  }
                }
              }
              if (param.getName().equals("String_Node_Str") || param.getName().equals("String_Node_Str")) {
                jobVersion=param.getValue();
              }
            }
          }
          for (          String jobId : jobIdSet) {
            addRelationShip(item,jobId,jobVersion,JOB_RELATION);
          }
        }
      }
    }
    if (oldProjectRelations != null) {
      Set<Relation> newProjectRelations=currentProjectItemsRelations.get(relation);
      if (oldProjectRelations.size() == newProjectRelations.size()) {
        relationsModified=false;
        for (        Relation newRelation : newProjectRelations) {
          if (!oldProjectRelations.contains(newRelation)) {
            relationsModified=true;
            break;
          }
        }
      }
      if (!relationsModified) {
        currentProjectItemsRelations.get(relation).addAll(oldProjectRelations);
      }
    }
    if (relationsModified && !modified) {
      modified=true;
    }
    if (!fromMigration && modified) {
      saveRelations();
    }
  }
}

Fixed version (ground truth):
public void addOrUpdateItem(Item item,boolean fromMigration){
  if (!loaded) {
    loadRelations();
  }
  ProcessType processType=null;
  if (item instanceof ProcessItem) {
    processType=((ProcessItem)item).getProcess();
  }
  if (item instanceof JobletProcessItem) {
    processType=((JobletProcessItem)item).getJobletProcess();
  }
  if (processType != null) {
    boolean relationsModified=true;
    Relation relation=new Relation();
    relation.setId(item.getProperty().getId());
    relation.setType(getTypeFromItem(item));
    relation.setVersion(item.getProperty().getVersion());
    Set<Relation> oldProjectRelations=null;
    if (currentProjectItemsRelations.containsKey(relation)) {
      oldProjectRelations=new HashSet<Relation>(currentProjectItemsRelations.get(relation));
      currentProjectItemsRelations.get(relation).clear();
    }
    clearItemsRelations(item);
    Boolean builtIn=null;
    String currentValue=null;
    String relationType=null;
    for (    Object o : processType.getContext()) {
      ContextType context=(ContextType)o;
      for (      Object o2 : context.getContextParameter()) {
        ContextParameterType contextParam=(ContextParameterType)o2;
        if (!StringUtils.isEmpty(contextParam.getRepositoryContextId())) {
          addRelationShip(item,contextParam.getRepositoryContextId(),LATEST_VERSION,CONTEXT_RELATION);
        }
      }
    }
    if (processType.getParameters() != null) {
      if (processType.getParameters().getRoutinesParameter() != null) {
        for (        Object o : processType.getParameters().getRoutinesParameter()) {
          RoutinesParameterType itemInfor=(RoutinesParameterType)o;
          addRelationShip(item,itemInfor.getName(),LATEST_VERSION,ROUTINE_RELATION);
        }
      }
      for (      Object o : processType.getParameters().getElementParameter()) {
        if (o instanceof ElementParameterType) {
          ElementParameterType param=(ElementParameterType)o;
          if (param.getName().startsWith("String_Node_Str")) {
            relationType=SCHEMA_RELATION;
          }
 else           if (param.getName().startsWith("String_Node_Str")) {
            relationType=PROPERTY_RELATION;
          }
 else           if (param.getName().startsWith("String_Node_Str")) {
            relationType=VALIDATION_RULE_RELATION;
          }
 else {
            builtIn=null;
            currentValue=null;
          }
          if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")) {
            builtIn=true;
            if (param.getValue().equals("String_Node_Str")) {
              builtIn=false;
            }
          }
          if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")) {
            currentValue=param.getValue();
          }
          if (builtIn != null && currentValue != null) {
            if (!builtIn) {
              addRelationShip(item,currentValue,LATEST_VERSION,relationType);
            }
            builtIn=null;
            currentValue=null;
          }
        }
      }
    }
    List<String> jobletsComponentsList=new ArrayList<String>();
    IComponentsService compService=(IComponentsService)GlobalServiceRegister.getDefault().getService(IComponentsService.class);
    for (    IComponent component : compService.getComponentsFactory().getComponents()) {
      if (component.getComponentType() == EComponentType.JOBLET) {
        jobletsComponentsList.add(component.getName());
      }
    }
    builtIn=null;
    currentValue=null;
    for (    Object o : processType.getNode()) {
      if (o instanceof NodeType) {
        NodeType currentNode=(NodeType)o;
        for (        Object o2 : currentNode.getElementParameter()) {
          if (o2 instanceof ElementParameterType) {
            ElementParameterType param=(ElementParameterType)o2;
            if (param.getName().startsWith("String_Node_Str")) {
              relationType=QUERY_RELATION;
            }
 else             if (param.getName().startsWith("String_Node_Str") || param.getName().startsWith("String_Node_Str")) {
              relationType=SCHEMA_RELATION;
            }
 else             if (param.getName().startsWith("String_Node_Str")) {
              relationType=PROPERTY_RELATION;
            }
 else             if (param.getName().startsWith("String_Node_Str")) {
              relationType=VALIDATION_RULE_RELATION;
            }
 else {
              builtIn=null;
              currentValue=null;
            }
            if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")|| param.getName().endsWith("String_Node_Str")) {
              builtIn=true;
              if (param.getValue().equals("String_Node_Str")) {
                builtIn=false;
              }
            }
            if (param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str") || param.getName().endsWith("String_Node_Str")|| param.getName().endsWith("String_Node_Str")) {
              currentValue=param.getValue();
            }
            if (builtIn != null && currentValue != null) {
              if (!builtIn) {
                addRelationShip(item,currentValue,LATEST_VERSION,relationType);
              }
              builtIn=null;
              currentValue=null;
            }
            if (param.getName().equals("String_Node_Str")) {
              for (              Object o3 : param.getElementValue()) {
                if (o3 instanceof ElementValueType && "String_Node_Str".equals(((ElementValueType)o3).getElementRef())) {
                  addRelationShip(item,((ElementValueType)o3).getValue(),LATEST_VERSION,SQLPATTERN_RELATION);
                }
              }
            }
            if (param.getField() != null && param.getField().equals(EParameterFieldType.SURVIVOR_RELATION.getName())) {
              String relatedID=param.getValue();
              addRelationShip(item,relatedID,LATEST_VERSION,SURVIVOR_RELATION);
            }
          }
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
          IDesignerMapperService service=(IDesignerMapperService)GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
          AbstractExternalData nodeData=currentNode.getNodeData();
          List<String> schemaIds=service.getRepositorySchemaIds(nodeData);
          if (schemaIds.size() > 0) {
            for (            String schemaId : schemaIds) {
              addRelationShip(item,schemaId,LATEST_VERSION,SCHEMA_RELATION);
            }
          }
        }
        if (jobletsComponentsList.contains(currentNode.getComponentName())) {
          String version=LATEST_VERSION;
          for (          Object o2 : currentNode.getElementParameter()) {
            if (o2 instanceof ElementParameterType) {
              ElementParameterType param=(ElementParameterType)o2;
              if (param.getName().equals("String_Node_Str")) {
                version=param.getValue();
              }
            }
          }
          IComponent cc=compService.getComponentsFactory().get(currentNode.getComponentName());
          IJobletProviderService service=null;
          if (PluginChecker.isJobLetPluginLoaded()) {
            service=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
          }
          Property property=service.getJobletComponentItem(cc);
          if (property != null)           addRelationShip(item,property.getId(),version,JOBLET_RELATION);
        }
        if ("String_Node_Str".equals(currentNode.getComponentName())) {
          String jobVersion=LATEST_VERSION;
          Set<String> jobIdSet=new HashSet<String>();
          for (          Object o2 : currentNode.getElementParameter()) {
            if (o2 instanceof ElementParameterType) {
              ElementParameterType param=(ElementParameterType)o2;
              if (param.getName().equals("String_Node_Str") || param.getName().equals("String_Node_Str")) {
                String jobIds=param.getValue();
                String[] jobsArr=jobIds.split(RelationshipItemBuilder.COMMA);
                for (                String jobId : jobsArr) {
                  if (StringUtils.isNotEmpty(jobId)) {
                    jobIdSet.add(jobId);
                  }
                }
              }
              if (param.getName().equals("String_Node_Str") || param.getName().equals("String_Node_Str")) {
                jobVersion=param.getValue();
              }
            }
          }
          for (          String jobId : jobIdSet) {
            addRelationShip(item,jobId,jobVersion,JOB_RELATION);
          }
        }
      }
    }
    if (oldProjectRelations != null) {
      Set<Relation> newProjectRelations=currentProjectItemsRelations.get(relation);
      if (oldProjectRelations.size() == newProjectRelations.size()) {
        relationsModified=false;
        for (        Relation newRelation : newProjectRelations) {
          if (!oldProjectRelations.contains(newRelation)) {
            relationsModified=true;
            break;
          }
        }
      }
      if (!relationsModified) {
        currentProjectItemsRelations.get(relation).addAll(oldProjectRelations);
      }
    }
    if (relationsModified && !modified) {
      modified=true;
    }
    if (!fromMigration && modified) {
      saveRelations();
    }
  }
}