Program: 120596
Project: 120596
Buggy source:
@Override protected Command createButtonCommand(Button button){
  FileItem repositoryFileItem=null;
  LinkRulesItem linkItem=null;
  Map<String,FileItem> repositoryFileItemMap=null;
  Map<String,LinkRulesItem> repositoryLinkRulesItemMap=null;
  String paramName=(String)button.getData(PARAMETER_NAME);
  IElementParameter param=elem.getElementParameter(paramName);
  Object data=button.getData(NAME);
  if (data != null && data.equals(REPOSITORY_CHOICE)) {
    IElementParameter dbTypeParam=null;
    if (elem instanceof org.talend.designer.core.ui.editor.process.Process || elem instanceof StatsAndLogsElement || elem instanceof ImplicitContextLoadElement) {
      if (EParameterName.PROPERTY_TYPE.getName().equals(paramName)) {
        dbTypeParam=elem.getElementParameter(EParameterName.DB_TYPE.getName());
      }
 else       if (JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()).equals(paramName)) {
        dbTypeParam=elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName()));
      }
    }
    RepositoryReviewDialog dialog=null;
    if (dbTypeParam != null) {
      String[] listRepositoryItems=dbTypeParam.getListRepositoryItems();
      dialog=new RepositoryReviewDialog(Display.getCurrent().getActiveShell(),ERepositoryObjectType.METADATA,param.getRepositoryValue(),listRepositoryItems);
    }
 else {
      dialog=new RepositoryReviewDialog(Display.getCurrent().getActiveShell(),ERepositoryObjectType.METADATA,param.getRepositoryValue());
    }
    if (dialog.open() == RepositoryReviewDialog.OK) {
      String id=dialog.getResult().getObject().getId();
      IElementParameter repositoryParam=param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
      String fullParamName=paramName + "String_Node_Str" + getRepositoryChoiceParamName();
      Connection repositoryConnection=null;
      IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
      Item item=null;
      try {
        IRepositoryViewObject repobj=factory.getLastVersion(id);
        if (repobj != null) {
          Property property=repobj.getProperty();
          if (property != null) {
            item=property.getItem();
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
      if (item != null) {
        if (item instanceof ConnectionItem) {
          repositoryConnection=((ConnectionItem)item).getConnection();
        }
      }
 else {
        repositoryConnection=null;
        if (repositoryParam != null) {
          item=dialog.getResult().getObject().getProperty().getItem();
          if (item instanceof ConnectionItem) {
            repositoryConnection=((ConnectionItem)item).getConnection();
          }
        }
      }
      if (repositoryConnection != null) {
        CompoundCommand compoundCommand=new CompoundCommand();
        RepositoryNode selectNode=dialog.getResult();
        ChangeValuesFromRepository changeValuesFromRepository=null;
        if (selectNode.getObjectType() == ERepositoryObjectType.SERVICESOPERATION && GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
          IESBService service=(IESBService)GlobalServiceRegister.getDefault().getService(IESBService.class);
          IProcess2 process=(IProcess2)RepositoryPlugin.getDefault().getDesignerCoreService().getCurrentProcess();
          String currentJobId=process.getProperty().getId();
          String serviceId=item.getProperty().getId();
          String portId=selectNode.getParent().getObject().getId();
          String operationId=selectNode.getObject().getId();
          changeValuesFromRepository=new ChangeValuesFromRepository(elem,repositoryConnection,param.getName() + "String_Node_Str" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),serviceId + "String_Node_Str" + portId+ "String_Node_Str"+ operationId);
          service.deleteOldRelation(currentJobId);
          service.updateOperation((INode)elem,serviceId + "String_Node_Str" + portId+ "String_Node_Str"+ operationId,selectNode);
        }
 else {
          changeValuesFromRepository=new ChangeValuesFromRepository(elem,repositoryConnection,fullParamName,id);
        }
        if (changeValuesFromRepository != null) {
          compoundCommand.add(changeValuesFromRepository);
        }
        updateDBType(compoundCommand,repositoryConnection);
        return compoundCommand;
      }
      if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
        repositoryFileItemMap=((MultipleThreadDynamicComposite)dynamicProperty).getRepositoryFileItemMap();
        repositoryLinkRulesItemMap=((MultipleThreadDynamicComposite)dynamicProperty).getRepositoryLinkRulesItemMap();
      }
      if (repositoryFileItemMap.containsKey(id)) {
        repositoryFileItem=repositoryFileItemMap.get(id);
      }
 else       if (repositoryLinkRulesItemMap.containsKey(id)) {
        linkItem=repositoryLinkRulesItemMap.get(id);
      }
 else {
        if (!repositoryFileItemMap.isEmpty()) {
          repositoryFileItem=repositoryFileItemMap.values().iterator().next();
        }
 else {
          repositoryFileItem=null;
        }
      }
      if (repositoryFileItem != null) {
        CompoundCommand compoundCommand=new CompoundCommand();
        final String showId=repositoryFileItem.getProperty().getId();
        Command command=new PropertyChangeCommand(elem,EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),showId);
        compoundCommand.add(command);
        return compoundCommand;
      }
      if (linkItem != null) {
        CompoundCommand compoundCommand=new CompoundCommand();
        final String showId=linkItem.getProperty().getId();
        Command command=new PropertyChangeCommand(elem,EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),showId);
        compoundCommand.add(command);
        return compoundCommand;
      }
    }
  }
 else {
    if (elem instanceof INode) {
      INode node=(INode)elem;
      final IRepositoryService repositoryService=CorePlugin.getDefault().getRepositoryService();
      if (param != null) {
        RepositoryNode realNode=null;
        String repositoryValue=param.getRepositoryValue();
        if (repositoryValue != null && repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_CONNECTIONS);
        }
 else         if (ERepositoryCategoryType.DELIMITED.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_DELIMITED);
        }
        if (ERepositoryCategoryType.POSITIONAL.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_POSITIONAL);
        }
        if (ERepositoryCategoryType.REGEX.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_REGEXP);
        }
        if (ERepositoryCategoryType.XML.getName().equals(repositoryValue) || repositoryValue.startsWith(ERepositoryCategoryType.XML.getName())) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_XML);
        }
        if (ERepositoryCategoryType.LDIF.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_LDIF);
        }
        if (ERepositoryCategoryType.EXCEL.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EXCEL);
        }
        if (ERepositoryCategoryType.GENERIC.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_GENERIC_SCHEMA);
        }
        if (ERepositoryCategoryType.LDAP.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_LDAP_SCHEMA);
        }
        if (ERepositoryCategoryType.WSDL.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
        }
        if (ERepositoryCategoryType.WEBSERVICE.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
        }
        if (ERepositoryCategoryType.SALESFORCE.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
        }
        if (ERepositoryCategoryType.EBCDIC.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EBCDIC);
        }
        if (ERepositoryCategoryType.MDM.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_MDMCONNECTION);
        }
        if (ERepositoryCategoryType.SAP.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAPCONNECTIONS);
        }
        if (ERepositoryCategoryType.SAPIDOC.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAP_IDOC);
        }
        if (ERepositoryCategoryType.HEADERFOOTER.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_HEADER_FOOTER);
        }
        if (ERepositoryCategoryType.BRMS.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_BRMS);
        }
        if (ERepositoryCategoryType.HL7.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_HL7);
        }
        if (realNode == null) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.getTypeFromKey(repositoryValue));
        }
        if (realNode != null) {
          final IMetadataService metadataService=CorePlugin.getDefault().getMetadataService();
          if (metadataService != null) {
            ConnectionItem connItem=metadataService.openMetadataConnection(true,realNode,node);
            if (connItem != null) {
              IElementParameter propertyParam=elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
              propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
              Command cmd=new ChangeValuesFromRepository(node,connItem.getConnection(),propertyParam.getName() + "String_Node_Str" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),connItem.getProperty().getId());
              executeCommand(cmd);
              if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
                ((MultipleThreadDynamicComposite)dynamicProperty).updateRepositoryList();
              }
            }
          }
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
@Override protected Command createButtonCommand(Button button){
  FileItem repositoryFileItem=null;
  LinkRulesItem linkItem=null;
  Map<String,FileItem> repositoryFileItemMap=null;
  Map<String,LinkRulesItem> repositoryLinkRulesItemMap=null;
  String paramName=(String)button.getData(PARAMETER_NAME);
  IElementParameter param=elem.getElementParameter(paramName);
  Object data=button.getData(NAME);
  if (data != null && data.equals(REPOSITORY_CHOICE)) {
    IElementParameter dbTypeParam=null;
    if (elem instanceof org.talend.designer.core.ui.editor.process.Process || elem instanceof StatsAndLogsElement || elem instanceof ImplicitContextLoadElement) {
      if (EParameterName.PROPERTY_TYPE.getName().equals(paramName)) {
        dbTypeParam=elem.getElementParameter(EParameterName.DB_TYPE.getName());
      }
 else       if (JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()).equals(paramName)) {
        dbTypeParam=elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName()));
      }
    }
    RepositoryReviewDialog dialog=null;
    if (dbTypeParam != null) {
      String[] listRepositoryItems=dbTypeParam.getListRepositoryItems();
      dialog=new RepositoryReviewDialog(Display.getCurrent().getActiveShell(),ERepositoryObjectType.METADATA,param.getRepositoryValue(),listRepositoryItems);
    }
 else {
      dialog=new RepositoryReviewDialog(Display.getCurrent().getActiveShell(),ERepositoryObjectType.METADATA,param.getRepositoryValue());
    }
    if (dialog.open() == RepositoryReviewDialog.OK) {
      String id=dialog.getResult().getObject().getId();
      IElementParameter repositoryParam=param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
      String fullParamName=paramName + "String_Node_Str" + getRepositoryChoiceParamName();
      Connection repositoryConnection=null;
      IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
      Item item=null;
      try {
        IRepositoryViewObject repobj=factory.getLastVersion(id);
        if (repobj != null) {
          Property property=repobj.getProperty();
          if (property != null) {
            item=property.getItem();
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
      if (item != null) {
        if (item instanceof ConnectionItem) {
          repositoryConnection=((ConnectionItem)item).getConnection();
        }
      }
 else {
        repositoryConnection=null;
        if (repositoryParam != null) {
          item=dialog.getResult().getObject().getProperty().getItem();
          if (item instanceof ConnectionItem) {
            repositoryConnection=((ConnectionItem)item).getConnection();
          }
        }
      }
      if (repositoryConnection != null) {
        CompoundCommand compoundCommand=new CompoundCommand();
        RepositoryNode selectNode=dialog.getResult();
        ChangeValuesFromRepository changeValuesFromRepository=null;
        if (selectNode.getObjectType() == ERepositoryObjectType.SERVICESOPERATION && GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
          IESBService service=(IESBService)GlobalServiceRegister.getDefault().getService(IESBService.class);
          IProcess2 process=(IProcess2)RepositoryPlugin.getDefault().getDesignerCoreService().getCurrentProcess();
          String currentJobId=process.getProperty().getId();
          String serviceId=item.getProperty().getId();
          String portId=selectNode.getParent().getObject().getId();
          String operationId=selectNode.getObject().getId();
          changeValuesFromRepository=new ChangeValuesFromRepository(elem,repositoryConnection,param.getName() + "String_Node_Str" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),serviceId + "String_Node_Str" + portId+ "String_Node_Str"+ operationId);
          service.deleteOldRelation(currentJobId);
          service.updateOperation((INode)elem,serviceId + "String_Node_Str" + portId+ "String_Node_Str"+ operationId,selectNode);
        }
 else {
          changeValuesFromRepository=new ChangeValuesFromRepository(elem,repositoryConnection,fullParamName,id);
        }
        if (changeValuesFromRepository != null) {
          compoundCommand.add(changeValuesFromRepository);
        }
        updateDBType(compoundCommand,repositoryConnection);
        return compoundCommand;
      }
      if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
        repositoryFileItemMap=((MultipleThreadDynamicComposite)dynamicProperty).getRepositoryFileItemMap();
        repositoryLinkRulesItemMap=((MultipleThreadDynamicComposite)dynamicProperty).getRepositoryLinkRulesItemMap();
      }
      if (repositoryFileItemMap.containsKey(id)) {
        repositoryFileItem=repositoryFileItemMap.get(id);
      }
 else       if (repositoryLinkRulesItemMap.containsKey(id)) {
        linkItem=repositoryLinkRulesItemMap.get(id);
      }
 else {
        if (!repositoryFileItemMap.isEmpty()) {
          repositoryFileItem=repositoryFileItemMap.values().iterator().next();
        }
 else {
          repositoryFileItem=null;
        }
      }
      if (repositoryFileItem == null && item instanceof FileItem) {
        repositoryFileItem=(FileItem)item;
      }
      if (repositoryFileItem != null) {
        CompoundCommand compoundCommand=new CompoundCommand();
        final String showId=repositoryFileItem.getProperty().getId();
        Command command=new PropertyChangeCommand(elem,EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),showId);
        compoundCommand.add(command);
        return compoundCommand;
      }
      if (linkItem != null) {
        CompoundCommand compoundCommand=new CompoundCommand();
        final String showId=linkItem.getProperty().getId();
        Command command=new PropertyChangeCommand(elem,EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),showId);
        compoundCommand.add(command);
        return compoundCommand;
      }
    }
  }
 else {
    if (elem instanceof INode) {
      INode node=(INode)elem;
      final IRepositoryService repositoryService=CorePlugin.getDefault().getRepositoryService();
      if (param != null) {
        RepositoryNode realNode=null;
        String repositoryValue=param.getRepositoryValue();
        if (repositoryValue != null && repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_CONNECTIONS);
        }
 else         if (ERepositoryCategoryType.DELIMITED.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_DELIMITED);
        }
        if (ERepositoryCategoryType.POSITIONAL.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_POSITIONAL);
        }
        if (ERepositoryCategoryType.REGEX.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_REGEXP);
        }
        if (ERepositoryCategoryType.XML.getName().equals(repositoryValue) || repositoryValue.startsWith(ERepositoryCategoryType.XML.getName())) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_XML);
        }
        if (ERepositoryCategoryType.LDIF.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_LDIF);
        }
        if (ERepositoryCategoryType.EXCEL.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EXCEL);
        }
        if (ERepositoryCategoryType.GENERIC.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_GENERIC_SCHEMA);
        }
        if (ERepositoryCategoryType.LDAP.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_LDAP_SCHEMA);
        }
        if (ERepositoryCategoryType.WSDL.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
        }
        if (ERepositoryCategoryType.WEBSERVICE.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
        }
        if (ERepositoryCategoryType.SALESFORCE.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
        }
        if (ERepositoryCategoryType.EBCDIC.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EBCDIC);
        }
        if (ERepositoryCategoryType.MDM.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_MDMCONNECTION);
        }
        if (ERepositoryCategoryType.SAP.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAPCONNECTIONS);
        }
        if (ERepositoryCategoryType.SAPIDOC.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAP_IDOC);
        }
        if (ERepositoryCategoryType.HEADERFOOTER.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_HEADER_FOOTER);
        }
        if (ERepositoryCategoryType.BRMS.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_BRMS);
        }
        if (ERepositoryCategoryType.HL7.getName().equals(repositoryValue)) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_HL7);
        }
        if (realNode == null) {
          realNode=(RepositoryNode)repositoryService.getRootRepositoryNode(ERepositoryObjectType.getTypeFromKey(repositoryValue));
        }
        if (realNode != null) {
          final IMetadataService metadataService=CorePlugin.getDefault().getMetadataService();
          if (metadataService != null) {
            ConnectionItem connItem=metadataService.openMetadataConnection(true,realNode,node);
            if (connItem != null) {
              IElementParameter propertyParam=elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
              propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
              Command cmd=new ChangeValuesFromRepository(node,connItem.getConnection(),propertyParam.getName() + "String_Node_Str" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(),connItem.getProperty().getId());
              executeCommand(cmd);
              if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
                ((MultipleThreadDynamicComposite)dynamicProperty).updateRepositoryList();
              }
            }
          }
        }
      }
    }
  }
  return null;
}