Program: 120186
Project: 120186
Buggy source:
private String generateNewQuery(){
  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;
  if (dbType != null && dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
    isJdbc=true;
    INode connectionNode=null;
    IElementParameter existConnection=node.getElementParameter("String_Node_Str");
    boolean useExistConnection=(existConnection == null ? false : (Boolean)existConnection.getValue());
    String driverClassName=node.getElementParameter("String_Node_Str").getValue().toString();
    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 (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=ExtractMetaDataUtils.getDbTypeByClassNameAndDriverJar(driverClassName,driverJarName);
    }
 else {
      dbType=ExtractMetaDataUtils.getDbTypeByClassName(driverClassName);
    }
    DatabaseConnection dbConn=null;
    if (dbType == null) {
      if (conn != null) {
        if (conn instanceof DatabaseConnection) {
          dbConn=(DatabaseConnection)conn;
        }
        driverClassName=DatabaseConnectionParameterUtil.getTrueParamValue(dbConn,driverClassName);
        dbType=ExtractMetaDataUtils.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.equals(EDatabaseTypeName.TERADATA.getDisplayName());
  }
  if (propertyType != null && !propertyType.equals(EmfComponent.REPOSITORY)) {
    for (    IElementParameter param : this.node.getElementParameters()) {
      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;
  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 ((isJdbc && conn != null) || dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || (StringUtils.isEmpty(schema) && dbType.equals(EDatabaseTypeName.ORACLE_RAC.getDisplayName()))) {
    schema=getDefaultSchema(realTableName);
  }
  if (conn != null && (EDatabaseTypeName.ORACLEFORSID.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLESN.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLE_RAC.equals(EDatabaseTypeName.getTypeFromDbType(dbType))|| EDatabaseTypeName.ORACLE_OCI.equals(EDatabaseTypeName.getTypeFromDbType(dbType)))) {
    schema=getDefaultSchema(realTableName);
  }
  if (conn == null) {
    Connection repositoryConnection;
    String connName=(String)node.getPropertyValue("String_Node_Str");
    for (    INode node : process.getGraphicalNodes()) {
      if (node.getElementName().equals(connName)) {
        final Object propertyValue=node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
        if (propertyValue != null) {
          IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
          Item item=null;
          try {
            IRepositoryViewObject repobj=factory.getLastVersion(propertyValue.toString());
            if (repobj != null) {
              Property property=repobj.getProperty();
              if (property != null) {
                item=property.getItem();
              }
            }
          }
 catch (          PersistenceException e) {
            ExceptionHandler.process(e);
          }
          if (item != null && item instanceof ConnectionItem) {
            repositoryConnection=((ConnectionItem)item).getConnection();
            conn=repositoryConnection;
          }
        }
      }
    }
    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(){
  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;
  if (dbType != null && dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
    isJdbc=true;
    INode connectionNode=null;
    IElementParameter existConnection=node.getElementParameter("String_Node_Str");
    boolean useExistConnection=(existConnection == null ? false : (Boolean)existConnection.getValue());
    String driverClassName=node.getElementParameter("String_Node_Str").getValue().toString();
    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 (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=ExtractMetaDataUtils.getDbTypeByClassNameAndDriverJar(driverClassName,driverJarName);
    }
 else {
      dbType=ExtractMetaDataUtils.getDbTypeByClassName(driverClassName);
    }
    DatabaseConnection dbConn=null;
    if (dbType == null) {
      if (conn != null) {
        if (conn instanceof DatabaseConnection) {
          dbConn=(DatabaseConnection)conn;
        }
        driverClassName=DatabaseConnectionParameterUtil.getTrueParamValue(dbConn,driverClassName);
        dbType=ExtractMetaDataUtils.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.equals(EDatabaseTypeName.TERADATA.getDisplayName());
  }
  if (propertyType != null && !propertyType.equals(EmfComponent.REPOSITORY)) {
    for (    IElementParameter param : this.node.getElementParameters()) {
      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;
  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 ((isJdbc && conn != null) || dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || (StringUtils.isEmpty(schema) && dbType.equals(EDatabaseTypeName.ORACLE_RAC.getDisplayName()))) {
    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);
}