Program: 138553
Project: 138553
Buggy source:
/** 
 * DOC xqliu Comment method "createIndicatorUnit".
 * @param pfile
 * @param modelElementIndicator
 * @param analysis
 * @param indicatorDefinition
 * @return
 */
public static TypedReturnCode<IndicatorUnit> createIndicatorUnit(IFile pfile,ModelElementIndicator modelElementIndicator,Analysis analysis,IndicatorDefinition indicatorDefinition){
  TypedReturnCode<IndicatorUnit> result=new TypedReturnCode<IndicatorUnit>();
  Pattern pattern=PatternResourceFileHelper.getInstance().findPattern(pfile);
  for (  Indicator indicator : modelElementIndicator.getIndicators()) {
    if (UDIHelper.getMatchingIndicatorName(indicatorDefinition,pattern).equals(indicator.getName())) {
      result.setOk(false);
      result.setMessage("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);
  }
  DbmsLanguage dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage(analysis);
  boolean isJavaEngin=ExecutionLanguage.JAVA.equals(analysis.getParameters().getExecutionLanguage());
  Expression returnExpression=dbmsLanguage.getRegexp(pattern,isJavaEngin);
  if (ExpressionType.REGEXP.getLiteral().equals(expressionType) && returnExpression == null) {
    result.setOk(false);
    result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
    return result;
  }
  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("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("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(IFile pfile,ModelElementIndicator modelElementIndicator,Analysis analysis,IndicatorDefinition indicatorDefinition){
  TypedReturnCode<IndicatorUnit> result=new TypedReturnCode<IndicatorUnit>();
  Pattern pattern=PatternResourceFileHelper.getInstance().findPattern(pfile);
  for (  Indicator indicator : modelElementIndicator.getIndicators()) {
    if (UDIHelper.getMatchingIndicatorName(indicatorDefinition,pattern).equals(indicator.getName())) {
      result.setOk(false);
      result.setMessage("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);
  }
  DbmsLanguage dbmsLanguage=DbmsLanguageFactory.createDbmsLanguage(analysis);
  boolean isJavaEngin=ExecutionLanguage.JAVA.equals(analysis.getParameters().getExecutionLanguage());
  Expression returnExpression=dbmsLanguage.getRegexp(pattern,isJavaEngin);
  if (ExpressionType.REGEXP.getLiteral().equals(expressionType) && returnExpression == null) {
    result.setOk(false);
    result.setMessage(DefaultMessagesImpl.getString("String_Node_Str"));
    return result;
  }
  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("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("String_Node_Str");
  result.setObject(addIndicatorUnit);
  return result;
}