Program: 119585
Project: 119585
Buggy source:
private String generateNewQuery(){
  ExtractMetaDataUtils extractMeta=ExtractMetaDataUtils.getInstance();
  if (realDBType != null) {
    dbType=realDBType;
  }
  if (node != null && node instanceof INode) {
    process=((INode)node).getProcess();
  }
  if (this.realTableId != null && this.dbNameAndDbTypeMap.containsKey(this.realTableId)) {
    dbType=this.dbNameAndDbTypeMap.get(this.realTableId);
  }
  if (dbType == null || dbType.equals("String_Node_Str")) {
    IElementParameter ptParam=node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
    if (ptParam != null && ptParam.getRepositoryValue() != null) {
      if (ptParam.getRepositoryValue().endsWith(EDatabaseTypeName.GENERAL_JDBC.getProduct())) {
        dbType=EDatabaseTypeName.GENERAL_JDBC.getDisplayName();
      }
    }
  }
  boolean isJdbc=false;
  INode connectionNode=null;
  IElementParameter existConnection=node.getElementParameter("String_Node_Str");
  boolean useExistConnection=(existConnection == null ? false : (Boolean)existConnection.getValue());
  if (useExistConnection) {
    IElementParameter connector=node.getElementParameter("String_Node_Str");
    if (connector != null) {
      String connectorValue=connector.getValue().toString();
      List<? extends INode> graphicalNodes=process.getGraphicalNodes();
      for (      INode node : graphicalNodes) {
        if (node.getUniqueName().equals(connectorValue)) {
          connectionNode=node;
          break;
        }
      }
    }
  }
  if (dbType != null && dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
    isJdbc=true;
    String driverClassName=node.getElementParameter("String_Node_Str").getValue().toString();
    if (connectionNode != null) {
      driverClassName=connectionNode.getElementParameter("String_Node_Str").getValue().toString();
    }
    driverClassName=TalendTextUtils.removeQuotes(driverClassName);
    if (driverClassName != null && !"String_Node_Str".equals(driverClassName)) {
      boolean isContextModeDriverClass=ContextParameterUtils.containContextVariables(driverClassName);
      if (isContextModeDriverClass) {
        driverClassName=JavaProcessUtil.getContextOriginalValue(process,driverClassName);
      }
    }
    if (driverClassName != null && !"String_Node_Str".equals(driverClassName)) {
      if (driverClassName.equals("String_Node_Str")) {
        driverClassName=EDatabase4DriverClassName.SYBASEASE.getDriverClass();
      }
    }
    String driverJarName=node.getElementParameter("String_Node_Str").getValue().toString();
    if (connectionNode != null) {
      driverJarName=connectionNode.getElementParameter("String_Node_Str").getValue().toString();
    }
    if (driverJarName != null && driverJarName.startsWith("String_Node_Str") && driverJarName.endsWith("String_Node_Str")) {
      driverJarName=driverJarName.substring(1,driverJarName.length() - 1);
      if (driverJarName != null && driverJarName.startsWith("String_Node_Str") && driverJarName.endsWith("String_Node_Str")) {
        driverJarName=driverJarName.substring(1,driverJarName.length() - 1);
      }
    }
    if (driverJarName != null && !"String_Node_Str".equals(driverJarName)) {
      boolean isContextMode=ContextParameterUtils.containContextVariables(driverJarName);
      if (isContextMode) {
        driverJarName=JavaProcessUtil.getContextOriginalValue(process,driverJarName);
      }
      dbType=extractMeta.getDbTypeByClassNameAndDriverJar(driverClassName,driverJarName);
    }
 else {
      dbType=extractMeta.getDbTypeByClassName(driverClassName);
    }
    DatabaseConnection dbConn=null;
    if (dbType == null) {
      if (conn != null) {
        if (conn instanceof DatabaseConnection) {
          dbConn=(DatabaseConnection)conn;
        }
        driverClassName=DatabaseConnectionParameterUtil.getTrueParamValue(dbConn,driverClassName);
        dbType=extractMeta.getDbTypeByClassName(driverClassName);
      }
    }
    if (dbType == null) {
      dbType=EDatabaseTypeName.ORACLE_OCI.getDisplayName();
    }
  }
  if (dbNameAndSchemaMap != null) {
    schema=this.dbNameAndSchemaMap.get(this.realTableId);
  }
  String propertyType=(String)node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
  boolean isTeradata=false;
  if (dbType != null) {
    isTeradata=dbType.equalsIgnoreCase(EDatabaseTypeName.TERADATA.getDisplayName());
  }
  if (propertyType != null && !propertyType.equals(EmfComponent.REPOSITORY)) {
    List<? extends IElementParameter> elementParameters=this.node.getElementParameters();
    if (useExistConnection) {
      elementParameters=connectionNode.getElementParameters();
    }
    for (    IElementParameter param : elementParameters) {
      if (param.getRepositoryValue() != null) {
        if ((!isTeradata && param.getRepositoryValue().equals("String_Node_Str")) || (isTeradata && param.getRepositoryValue().equals("String_Node_Str"))) {
          schema=(String)param.getValue();
          schema=schema.replace("String_Node_Str","String_Node_Str");
          schema=schema.replace("String_Node_Str","String_Node_Str");
          break;
        }
      }
    }
  }
 else   if (schema == null) {
    IElementParameter param=node.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    if (param != null) {
      try {
        IRepositoryViewObject object=DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getLastVersion((String)param.getValue());
        if (object != null) {
          Item item=object.getProperty().getItem();
          if (item != null && item instanceof DatabaseConnectionItem) {
            if (isTeradata) {
              schema=(String)RepositoryToComponentProperty.getValue(((DatabaseConnectionItem)item).getConnection(),"String_Node_Str",null);
            }
 else {
              schema=(String)RepositoryToComponentProperty.getValue(((DatabaseConnectionItem)item).getConnection(),"String_Node_Str",null);
            }
            schema=TalendTextUtils.removeQuotes(schema);
          }
        }
      }
 catch (      PersistenceException e) {
      }
    }
  }
  if (conn instanceof DatabaseConnection && conn.isContextMode()) {
    schema=DatabaseConnectionParameterUtil.getContextTrueValue((DatabaseConnection)conn,schema);
  }
  String newQuery=null;
  if (fillCorrectMetadataTable()) {
    return TalendQuoteUtils.addQuotes("String_Node_Str");
  }
  realTableName=QueryUtil.getTableName(node,newOutputMetadataTable,schema,dbType,realTableName);
  if (realTableName.startsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.endsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.length() > 2) {
    realTableName=realTableName.substring(1,realTableName.length() - 1);
  }
  if (conn != null && (isJdbc || dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || (StringUtils.isEmpty(schema) && (EDatabaseTypeName.ORACLE_CUSTOM.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLEFORSID.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLESN.equals(EDatabaseTypeName.getTypeFromDbType(dbType))|| EDatabaseTypeName.ORACLE_OCI.equals(EDatabaseTypeName.getTypeFromDbType(dbType)))))) {
    schema=getDefaultSchema(realTableName);
  }
  newQuery=QueryUtil.generateNewQuery(node,newOutputMetadataTable,isJdbc,dbType,schema,realTableName);
  if (whereClause != null) {
    newQuery=newQuery.substring(0,newQuery.length() - 1) + whereClause + "String_Node_Str";
  }
  return TalendTextUtils.addSQLQuotes(newQuery);
}

Fixed version (ground truth):
private String generateNewQuery(){
  ExtractMetaDataUtils extractMeta=ExtractMetaDataUtils.getInstance();
  if (realDBType != null) {
    dbType=realDBType;
  }
  if (node != null && node instanceof INode) {
    process=((INode)node).getProcess();
  }
  if (this.realTableId != null && this.dbNameAndDbTypeMap.containsKey(this.realTableId)) {
    dbType=this.dbNameAndDbTypeMap.get(this.realTableId);
  }
  if (dbType == null || dbType.equals("String_Node_Str")) {
    IElementParameter ptParam=node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
    if (ptParam != null && ptParam.getRepositoryValue() != null) {
      if (ptParam.getRepositoryValue().endsWith(EDatabaseTypeName.GENERAL_JDBC.getProduct())) {
        dbType=EDatabaseTypeName.GENERAL_JDBC.getDisplayName();
      }
    }
  }
  boolean isJdbc=false;
  INode connectionNode=null;
  IElementParameter existConnection=node.getElementParameter("String_Node_Str");
  boolean useExistConnection=(existConnection == null ? false : (Boolean)existConnection.getValue());
  if (useExistConnection) {
    IElementParameter connector=node.getElementParameter("String_Node_Str");
    if (connector != null) {
      String connectorValue=connector.getValue().toString();
      List<? extends INode> graphicalNodes=process.getGraphicalNodes();
      for (      INode node : graphicalNodes) {
        if (node.getUniqueName().equals(connectorValue)) {
          connectionNode=node;
          break;
        }
      }
    }
  }
  if (dbType != null && dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
    isJdbc=true;
    String driverClassName=node.getElementParameter("String_Node_Str").getValue().toString();
    if (connectionNode != null) {
      driverClassName=connectionNode.getElementParameter("String_Node_Str").getValue().toString();
    }
    driverClassName=TalendTextUtils.removeQuotes(driverClassName);
    if (driverClassName != null && !"String_Node_Str".equals(driverClassName)) {
      boolean isContextModeDriverClass=ContextParameterUtils.containContextVariables(driverClassName);
      if (isContextModeDriverClass) {
        driverClassName=JavaProcessUtil.getContextOriginalValue(process,driverClassName);
      }
    }
    if (driverClassName != null && !"String_Node_Str".equals(driverClassName)) {
      if (driverClassName.equals("String_Node_Str")) {
        driverClassName=EDatabase4DriverClassName.SYBASEASE.getDriverClass();
      }
    }
    String driverJarName=node.getElementParameter("String_Node_Str").getValue().toString();
    if (connectionNode != null) {
      driverJarName=connectionNode.getElementParameter("String_Node_Str").getValue().toString();
    }
    if (driverJarName != null && driverJarName.startsWith("String_Node_Str") && driverJarName.endsWith("String_Node_Str")) {
      driverJarName=driverJarName.substring(1,driverJarName.length() - 1);
      if (driverJarName != null && driverJarName.startsWith("String_Node_Str") && driverJarName.endsWith("String_Node_Str")) {
        driverJarName=driverJarName.substring(1,driverJarName.length() - 1);
      }
    }
    if (driverJarName != null && !"String_Node_Str".equals(driverJarName)) {
      boolean isContextMode=ContextParameterUtils.containContextVariables(driverJarName);
      if (isContextMode) {
        driverJarName=JavaProcessUtil.getContextOriginalValue(process,driverJarName);
      }
      dbType=extractMeta.getDbTypeByClassNameAndDriverJar(driverClassName,driverJarName);
    }
 else {
      dbType=extractMeta.getDbTypeByClassName(driverClassName);
    }
    DatabaseConnection dbConn=null;
    if (dbType == null) {
      if (conn != null) {
        if (conn instanceof DatabaseConnection) {
          dbConn=(DatabaseConnection)conn;
        }
        driverClassName=DatabaseConnectionParameterUtil.getTrueParamValue(dbConn,driverClassName);
        dbType=extractMeta.getDbTypeByClassName(driverClassName);
      }
    }
    if (dbType == null) {
      dbType=EDatabaseTypeName.ORACLE_OCI.getDisplayName();
    }
  }
  if (dbNameAndSchemaMap != null) {
    schema=this.dbNameAndSchemaMap.get(this.realTableId);
  }
  String propertyType=(String)node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
  boolean isTeradata=false;
  if (dbType != null) {
    isTeradata=dbType.equalsIgnoreCase(EDatabaseTypeName.TERADATA.getDisplayName());
  }
  if (propertyType != null && !propertyType.equals(EmfComponent.REPOSITORY)) {
    List<? extends IElementParameter> elementParameters=this.node.getElementParameters();
    if (useExistConnection) {
      elementParameters=connectionNode.getElementParameters();
    }
    for (    IElementParameter param : elementParameters) {
      if (param.getRepositoryValue() != null) {
        if ((!isTeradata && param.getRepositoryValue().equals("String_Node_Str")) || (isTeradata && param.getRepositoryValue().equals("String_Node_Str"))) {
          schema=(String)param.getValue();
          schema=schema.replace("String_Node_Str","String_Node_Str");
          schema=schema.replace("String_Node_Str","String_Node_Str");
          break;
        }
      }
    }
  }
 else   if (schema == null) {
    IElementParameter param=node.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    if (param != null) {
      try {
        IRepositoryViewObject object=DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getLastVersion((String)param.getValue());
        if (object != null) {
          Item item=object.getProperty().getItem();
          if (item != null && item instanceof DatabaseConnectionItem) {
            if (isTeradata) {
              schema=(String)RepositoryToComponentProperty.getValue(((DatabaseConnectionItem)item).getConnection(),"String_Node_Str",null);
            }
 else {
              schema=(String)RepositoryToComponentProperty.getValue(((DatabaseConnectionItem)item).getConnection(),"String_Node_Str",null);
            }
            schema=TalendTextUtils.removeQuotes(schema);
          }
        }
      }
 catch (      PersistenceException e) {
      }
    }
  }
  if (conn instanceof DatabaseConnection && conn.isContextMode()) {
    schema=DatabaseConnectionParameterUtil.getContextTrueValue((DatabaseConnection)conn,schema);
  }
  String newQuery=null;
  fillCorrectMetadataTable();
  realTableName=QueryUtil.getTableName(node,newOutputMetadataTable,schema,dbType,realTableName);
  if (realTableName.startsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.endsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.length() > 2) {
    realTableName=realTableName.substring(1,realTableName.length() - 1);
  }
  if (conn != null && (isJdbc || dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || (StringUtils.isEmpty(schema) && (EDatabaseTypeName.ORACLE_CUSTOM.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLEFORSID.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLESN.equals(EDatabaseTypeName.getTypeFromDbType(dbType))|| EDatabaseTypeName.ORACLE_OCI.equals(EDatabaseTypeName.getTypeFromDbType(dbType)))))) {
    schema=getDefaultSchema(realTableName);
  }
  newQuery=QueryUtil.generateNewQuery(node,newOutputMetadataTable,isJdbc,dbType,schema,realTableName);
  if (whereClause != null) {
    newQuery=newQuery.substring(0,newQuery.length() - 1) + whereClause + "String_Node_Str";
  }
  return TalendTextUtils.addSQLQuotes(newQuery);
}