Program: 123844
Project: 123844
Buggy source:
/** 
 * DOC qzhang Comment method "openSQLBuilder".
 * @param repositoryType
 * @param propertyName
 * @param query
 */
protected String openSQLBuilder(String repositoryType,String propertyName,String query){
  if (repositoryType.equals(EmfComponent.BUILTIN)) {
    connParameters.setQuery(query);
    if (connParameters.isShowConfigParamDialog()) {
      if (!isUseExistingConnection()) {
        initConnectionParametersWithContext(elem,part.getProcess().getContextManager().getDefaultContext());
      }
 else {
        initConnectionParametersWithContext(connectionNode,part.getProcess().getContextManager().getDefaultContext());
      }
    }
    openSqlBuilderBuildIn(connParameters,propertyName);
  }
 else   if (repositoryType.equals(EmfComponent.REPOSITORY)) {
    String repositoryName2="String_Node_Str";
    String repositoryId=null;
    IElementParameter memoParam=elem.getElementParameter(propertyName);
    IElementParameter repositoryParam=elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE,memoParam.getCategory());
    if (repositoryParam != null) {
      IElementParameter itemFromRepository=repositoryParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
      String value=(String)itemFromRepository.getValue();
      repositoryId=value;
      IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
      try {
        IRepositoryViewObject repobj=factory.getLastVersion(value);
        if (repobj != null) {
          Property property=repobj.getProperty();
          if (property != null) {
            repositoryName2=property.getLabel();
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
    }
    if (repositoryName2 == null || repositoryName2.length() == 0) {
      MessageDialog.openError(composite.getShell(),Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
      return null;
    }
    String processName="String_Node_Str";
    String key="String_Node_Str";
    if (elem instanceof Node) {
      processName=((Node)elem).getProcess().getName();
      key=processName + ((Node)elem).getUniqueName();
    }
 else     if (elem instanceof IProcess) {
      processName=((IProcess)elem).getName();
      key=processName;
    }
    key+=repositoryName2;
    final Dialog builderDialog=sqlbuilers.get(key);
    if (!composite.isDisposed() && builderDialog != null && builderDialog.getShell() != null && !builderDialog.getShell().isDisposed()) {
      builderDialog.getShell().setActive();
    }
 else {
      connParameters.setRepositoryName(repositoryName2);
      if (repositoryId != null) {
        connParameters.setRepositoryId(repositoryId);
      }
      Shell parentShell=new Shell(composite.getShell().getDisplay());
      String nodeLabel=null;
      if (elem instanceof Node) {
        nodeLabel=(String)((Node)elem).getElementParameter(EParameterName.LABEL.getName()).getValue();
      }
      TextUtil.setDialogTitle(processName,nodeLabel,elem.getElementName());
      ISQLBuilderService service=(ISQLBuilderService)GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
      connParameters.setQuery(query);
      Dialog sqlBuilder=service.openSQLBuilderDialog(parentShell,processName,connParameters);
      sqlbuilers.put(key,sqlBuilder);
      if (Window.OK == sqlBuilder.open()) {
        if (!composite.isDisposed() && !connParameters.isNodeReadOnly()) {
          String sql=connParameters.getQuery();
          if (!connParameters.getIfContextButtonCheckedFromBuiltIn()) {
            sql=QueryUtil.checkAndAddQuotes(sql);
          }
          return sql;
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * DOC qzhang Comment method "openSQLBuilder".
 * @param repositoryType
 * @param propertyName
 * @param query
 */
protected String openSQLBuilder(String repositoryType,String propertyName,String query){
  if (repositoryType.equals(EmfComponent.BUILTIN)) {
    connParameters.setQuery(query);
    if (connParameters.isShowConfigParamDialog()) {
      if (!isUseExistingConnection()) {
        initConnectionParametersWithContext(elem,part.getProcess().getContextManager().getDefaultContext());
      }
 else {
        initConnectionParametersWithContext(connectionNode,part.getProcess().getContextManager().getDefaultContext());
      }
    }
    openSqlBuilderBuildIn(connParameters,propertyName);
  }
 else   if (repositoryType.equals(EmfComponent.REPOSITORY)) {
    String repositoryName2="String_Node_Str";
    String repositoryId=null;
    IElementParameter memoParam=elem.getElementParameter(propertyName);
    IElementParameter repositoryParam=elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE,memoParam.getCategory());
    if (repositoryParam != null) {
      IElementParameter itemFromRepository=repositoryParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
      String value=(String)itemFromRepository.getValue();
      repositoryId=value;
      IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
      try {
        IRepositoryViewObject repobj=factory.getLastVersion(value);
        if (repobj != null) {
          Property property=repobj.getProperty();
          if (property != null) {
            repositoryName2=property.getLabel();
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
    }
    if (repositoryName2 == null || repositoryName2.length() == 0) {
      MessageDialog.openError(composite.getShell(),Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
      return null;
    }
    String processName="String_Node_Str";
    String key="String_Node_Str";
    if (elem instanceof Node) {
      processName=((Node)elem).getProcess().getName();
      key=processName + ((Node)elem).getUniqueName();
    }
 else     if (elem instanceof IProcess) {
      processName=((IProcess)elem).getName();
      key=processName;
    }
    key+=repositoryName2;
    final Dialog builderDialog=sqlbuilers.get(key);
    if (!composite.isDisposed() && builderDialog != null && builderDialog.getShell() != null && !builderDialog.getShell().isDisposed()) {
      builderDialog.getShell().setActive();
    }
 else {
      connParameters.setRepositoryName(repositoryName2);
      if (repositoryId != null) {
        connParameters.setRepositoryId(repositoryId);
      }
      Shell parentShell=new Shell(composite.getShell().getDisplay());
      String nodeLabel=null;
      if (elem instanceof Node) {
        nodeLabel=(String)((Node)elem).getElementParameter(EParameterName.LABEL.getName()).getValue();
      }
      TextUtil.setDialogTitle(processName,nodeLabel,elem.getElementName());
      ISQLBuilderService service=(ISQLBuilderService)GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
      connParameters.setQuery(query);
      connParameters.setFirstOpenSqlBuilder(true);
      Dialog sqlBuilder=service.openSQLBuilderDialog(parentShell,processName,connParameters);
      sqlbuilers.put(key,sqlBuilder);
      if (Window.OK == sqlBuilder.open()) {
        if (!composite.isDisposed() && !connParameters.isNodeReadOnly()) {
          String sql=connParameters.getQuery();
          if (!connParameters.getIfContextButtonCheckedFromBuiltIn()) {
            sql=QueryUtil.checkAndAddQuotes(sql);
          }
          return sql;
        }
      }
    }
  }
  return null;
}