Program: 138231
Project: 138231
Buggy source:
/** 
 * DOC xqliu Comment method "createIndicatorUnit".
 * @param pfile
 * @param modelElementIndicator
 * @param analysis
 * @param indicatorDefinition
 * @return
 */
public static TypedReturnCode<IndicatorUnit> createIndicatorUnit(Pattern pattern,ModelElementIndicator modelElementIndicator,Analysis analysis,IndicatorDefinition indicatorDefinition){
  TypedReturnCode<IndicatorUnit> result=new TypedReturnCode<IndicatorUnit>();
  for (  Indicator indicator : modelElementIndicator.getIndicators()) {
    if (UDIHelper.getMatchingIndicatorName(indicatorDefinition,pattern).equals(indicator.getName())) {
      result.setOk(false);
      result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
      return result;
    }
  }
  Indicator patternMatchingIndicator=null;
  String expressionType=DomainHelper.getExpressionType(pattern);
  boolean isSQLPattern=(ExpressionType.SQL_LIKE.getLiteral().equals(expressionType));
  if (indicatorDefinition != null) {
    patternMatchingIndicator=UDIFactory.createUserDefIndicator(indicatorDefinition,pattern);
  }
 else {
    patternMatchingIndicator=isSQLPattern ? PatternIndicatorFactory.createSqlPatternMatchingIndicator(pattern) : PatternIndicatorFactory.createRegexpMatchingIndicator(pattern);
  }
  IEditorPart theEdit=CorePlugin.getDefault().getCurrentActiveEditor();
  if (theEdit != null && theEdit instanceof AnalysisEditor && analysis.getContext().getConnection() == null) {
    theEdit.doSave(null);
  }
  ExecutionLanguage executionLanguage=analysis.getParameters().getExecutionLanguage();
  DbmsLanguage dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage(analysis);
  if (dbmsLanguage.isSql()) {
    MessageUI.openWarning(DefaultMessagesImpl.getString("String_Node_Str"));
    result.setOk(false);
    return result;
  }
  boolean isJavaEngin=ExecutionLanguage.JAVA.equals(executionLanguage);
  Expression returnExpression=dbmsLanguage.getRegexp(pattern,isJavaEngin);
  if (ExpressionType.REGEXP.getLiteral().equals(expressionType) && returnExpression == null) {
    String executeType=isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
    boolean openPattern=MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DefaultMessagesImpl.getString("String_Node_Str"),DefaultMessagesImpl.getString("String_Node_Str",executeType));
    if (openPattern) {
      RepositoryNode node=(RepositoryNode)RepositoryNodeHelper.recursiveFind(pattern);
      if (RepositoryNodeHelper.canOpenEditor(node)) {
        new OpenItemEditorAction(node).run();
      }
    }
    result.setOk(false);
    return result;
  }
  String javaRexex=DomainHelper.getJavaRegexp(pattern);
  if (javaRexex == null) {
  }
  DataManager dm=analysis.getContext().getConnection();
  if (dm != null) {
    TypedReturnCode<java.sql.Connection> trc=JavaSqlFactory.createConnection((Connection)dm);
    boolean isDelimitedFileConnection=ConnectionUtils.isDelimitedFileConnection((DataProvider)dm);
    if (trc != null) {
      java.sql.Connection conn=trc.getObject();
      if (isDelimitedFileConnection) {
        dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage((DelimitedFileConnection)dm);
      }
 else {
        try {
          SoftwareSystem softwareSystem=DatabaseContentRetriever.getSoftwareSystem(conn);
          dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage(softwareSystem);
        }
 catch (        SQLException e) {
          log.error(e,e);
        }
      }
    }
    if (!(isSQLPattern || DefinitionHandler.getInstance().canRunRegularExpressionMatchingIndicator(dbmsLanguage,isJavaEngin,pattern) || isDelimitedFileConnection)) {
      result.setOk(false);
      result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
      return result;
    }
  }
  if (indicatorDefinition == null) {
    if (!DefinitionHandler.getInstance().setDefaultIndicatorDefinition(patternMatchingIndicator)) {
      log.error(DefaultMessagesImpl.getString("String_Node_Str",patternMatchingIndicator.getName()));
    }
  }
 else {
    patternMatchingIndicator.setIndicatorDefinition(indicatorDefinition);
  }
  IndicatorEnum type=IndicatorEnum.findIndicatorEnum(patternMatchingIndicator.eClass());
  IndicatorUnit addIndicatorUnit=modelElementIndicator.addSpecialIndicator(type,patternMatchingIndicator);
  DependenciesHandler.getInstance().setUsageDependencyOn(analysis,pattern);
  result.setOk(true);
  result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
  result.setObject(addIndicatorUnit);
  return result;
}

Fixed version (ground truth):
/** 
 * DOC xqliu Comment method "createIndicatorUnit".
 * @param pfile
 * @param modelElementIndicator
 * @param analysis
 * @param indicatorDefinition
 * @return
 */
public static TypedReturnCode<IndicatorUnit> createIndicatorUnit(Pattern pattern,ModelElementIndicator modelElementIndicator,Analysis analysis,IndicatorDefinition indicatorDefinition){
  TypedReturnCode<IndicatorUnit> result=new TypedReturnCode<IndicatorUnit>();
  for (  Indicator indicator : modelElementIndicator.getIndicators()) {
    if (UDIHelper.getMatchingIndicatorName(indicatorDefinition,pattern).equals(indicator.getName())) {
      result.setOk(false);
      result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
      return result;
    }
  }
  Indicator patternMatchingIndicator=null;
  String expressionType=DomainHelper.getExpressionType(pattern);
  boolean isSQLPattern=(ExpressionType.SQL_LIKE.getLiteral().equals(expressionType));
  if (indicatorDefinition != null) {
    patternMatchingIndicator=UDIFactory.createUserDefIndicator(indicatorDefinition,pattern);
  }
 else {
    patternMatchingIndicator=isSQLPattern ? PatternIndicatorFactory.createSqlPatternMatchingIndicator(pattern) : PatternIndicatorFactory.createRegexpMatchingIndicator(pattern);
  }
  IEditorPart theEdit=CorePlugin.getDefault().getCurrentActiveEditor();
  if (theEdit != null && theEdit instanceof AnalysisEditor && analysis.getContext().getConnection() == null) {
    theEdit.doSave(null);
  }
  ExecutionLanguage executionLanguage=analysis.getParameters().getExecutionLanguage();
  DbmsLanguage dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage(analysis);
  if (dbmsLanguage.isSql()) {
    MessageUI.openWarning(DefaultMessagesImpl.getString("String_Node_Str"));
    result.setOk(false);
    return result;
  }
  boolean isJavaEngin=ExecutionLanguage.JAVA.equals(executionLanguage);
  Expression returnExpression=dbmsLanguage.getRegexp(pattern,isJavaEngin);
  if (ExpressionType.REGEXP.getLiteral().equals(expressionType) && returnExpression == null) {
    String executeType=isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
    boolean openPattern=MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),DefaultMessagesImpl.getString("String_Node_Str"),DefaultMessagesImpl.getString("String_Node_Str",executeType));
    if (openPattern) {
      RepositoryNode node=(RepositoryNode)RepositoryNodeHelper.recursiveFind(pattern);
      if (RepositoryNodeHelper.canOpenEditor(node)) {
        new OpenItemEditorAction(node).run();
      }
    }
    result.setOk(false);
    return result;
  }
  String javaRexex=DomainHelper.getJavaRegexp(pattern);
  if (javaRexex == null) {
  }
  DataManager dm=analysis.getContext().getConnection();
  if (dm != null) {
    TypedReturnCode<java.sql.Connection> trc=JavaSqlFactory.createConnection((Connection)dm);
    boolean isDelimitedFileConnection=ConnectionUtils.isDelimitedFileConnection((DataProvider)dm);
    boolean isMdmConnection=ConnectionUtils.isMdmConnection((DataProvider)dm);
    if (trc != null) {
      java.sql.Connection conn=trc.getObject();
      if (isDelimitedFileConnection) {
        dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage((DelimitedFileConnection)dm);
      }
 else       if (isMdmConnection) {
        dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage((MDMConnection)dm);
      }
 else {
        try {
          SoftwareSystem softwareSystem=DatabaseContentRetriever.getSoftwareSystem(conn);
          dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage(softwareSystem);
        }
 catch (        SQLException e) {
          log.error(e,e);
        }
      }
    }
    if (!(isSQLPattern || DefinitionHandler.getInstance().canRunRegularExpressionMatchingIndicator(dbmsLanguage,isJavaEngin,pattern) || isDelimitedFileConnection)) {
      result.setOk(false);
      result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
      return result;
    }
  }
  if (indicatorDefinition == null) {
    if (!DefinitionHandler.getInstance().setDefaultIndicatorDefinition(patternMatchingIndicator)) {
      log.error(DefaultMessagesImpl.getString("String_Node_Str",patternMatchingIndicator.getName()));
    }
  }
 else {
    patternMatchingIndicator.setIndicatorDefinition(indicatorDefinition);
  }
  IndicatorEnum type=IndicatorEnum.findIndicatorEnum(patternMatchingIndicator.eClass());
  IndicatorUnit addIndicatorUnit=modelElementIndicator.addSpecialIndicator(type,patternMatchingIndicator);
  DependenciesHandler.getInstance().setUsageDependencyOn(analysis,pattern);
  result.setOk(true);
  result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
  result.setObject(addIndicatorUnit);
  return result;
}