Program: 137743
Project: 137743
Buggy source:
protected String getFreqRowsStatement(){
  IndicatorDefinition indicatorDefinition=this.indicator.getIndicatorDefinition();
  if (indicatorDefinition instanceof UDIndicatorDefinition) {
    String sql=PluginConstant.EMPTY_STRING;
    EList<TdExpression> list=((UDIndicatorDefinition)indicatorDefinition).getViewRowsExpression();
    TdExpression tdExp=DbmsLanguage.getSqlExpression(indicatorDefinition,dbmsLanguage.getDbmsName(),list,dbmsLanguage.getDbVersion());
    sql=tdExp.getBody();
    String dataFilterClause=getDataFilterClause();
    sql=sql.replace(GenericSQLHandler.WHERE_CLAUSE,dbmsLanguage.where() + dataFilterClause);
    sql=sql.replace(GenericSQLHandler.AND_WHERE_CLAUSE,PluginConstant.EMPTY_STRING.equals(dataFilterClause) ? PluginConstant.EMPTY_STRING : dbmsLanguage.and() + dataFilterClause);
    String tableName=getFullyQualifiedTableName(this.indicator.getAnalyzedElement());
    sql=sql.replace(GenericSQLHandler.TABLE_NAME,tableName);
    sql=sql.replace(GenericSQLHandler.UDI_INDICATOR_VALUE,this.indicator.getAnalyzedElement().getName());
    return sql;
  }
  String clause=PluginConstant.EMPTY_STRING;
  TdColumn column=(TdColumn)indicator.getAnalyzedElement();
  int javaType=column.getSqlDataType().getJavaDataType();
  if (Java2SqlType.isTextInSQL(javaType)) {
    clause=getInstantiatedClause();
  }
 else   if (Java2SqlType.isDateInSQL(javaType)) {
    if (entity.isLabelNull()) {
      clause=getInstantiatedClause();
    }
 else {
      IndicatorParameters parameters=indicator.getParameters();
      if (parameters != null) {
        DateParameters dateParameters=parameters.getDateParameters();
        if (dateParameters != null) {
          DateGrain dateGrain=dateParameters.getDateAggregationType();
          clause=entity.isLabelNull() ? getInstantiatedClause() : getClauseWithDate(dateGrain,clause);
        }
 else {
          clause=getInstantiatedClause();
        }
      }
 else {
        clause=getInstantiatedClause();
      }
    }
  }
 else   if (Java2SqlType.isNumbericInSQL(javaType)) {
    IndicatorParameters parameters=indicator.getParameters();
    if (parameters != null) {
      Domain bins=parameters.getBins();
      if (bins != null) {
        final EList<RangeRestriction> ranges=bins.getRanges();
        for (        RangeRestriction rangeRestriction : ranges) {
          if (entity.getLabel() != null && entity.getLabel().equals(rangeRestriction.getName())) {
            clause=createWhereClause(rangeRestriction);
            break;
          }
        }
      }
 else {
        clause=getInstantiatedClause();
      }
    }
 else {
      clause=getInstantiatedClause();
    }
  }
 else {
    clause=getDefaultQuotedStatement(PluginConstant.EMPTY_STRING);
  }
  return "String_Node_Str" + getFullyQualifiedTableName(column) + dbmsLanguage.where()+ inBrackets(clause)+ andDataFilterClause();
}

Fixed version (ground truth):
protected String getFreqRowsStatement(){
  IndicatorDefinition indicatorDefinition=this.indicator.getIndicatorDefinition();
  if (indicatorDefinition instanceof UDIndicatorDefinition) {
    return getQueryForUDIndicator(indicatorDefinition);
  }
  String clause=PluginConstant.EMPTY_STRING;
  TdColumn column=(TdColumn)indicator.getAnalyzedElement();
  int javaType=column.getSqlDataType().getJavaDataType();
  if (Java2SqlType.isTextInSQL(javaType)) {
    clause=getInstantiatedClause();
  }
 else   if (Java2SqlType.isDateInSQL(javaType)) {
    if (entity.isLabelNull()) {
      clause=getInstantiatedClause();
    }
 else {
      IndicatorParameters parameters=indicator.getParameters();
      if (parameters != null) {
        DateParameters dateParameters=parameters.getDateParameters();
        if (dateParameters != null) {
          DateGrain dateGrain=dateParameters.getDateAggregationType();
          clause=entity.isLabelNull() ? getInstantiatedClause() : getClauseWithDate(dateGrain,clause);
        }
 else {
          clause=getInstantiatedClause();
        }
      }
 else {
        clause=getInstantiatedClause();
      }
    }
  }
 else   if (Java2SqlType.isNumbericInSQL(javaType)) {
    IndicatorParameters parameters=indicator.getParameters();
    if (parameters != null) {
      Domain bins=parameters.getBins();
      if (bins != null) {
        final EList<RangeRestriction> ranges=bins.getRanges();
        for (        RangeRestriction rangeRestriction : ranges) {
          if (entity.getLabel() != null && entity.getLabel().equals(rangeRestriction.getName())) {
            clause=createWhereClause(rangeRestriction);
            break;
          }
        }
      }
 else {
        clause=getInstantiatedClause();
      }
    }
 else {
      clause=getInstantiatedClause();
    }
  }
 else {
    clause=getDefaultQuotedStatement(PluginConstant.EMPTY_STRING);
  }
  return "String_Node_Str" + getFullyQualifiedTableName(column) + dbmsLanguage.where()+ inBrackets(clause)+ andDataFilterClause();
}