Program: 24990
Project: 24990
Buggy source:
/** 
 * <p>Tell whether the specified table exists in the database. To do so, it is using the given   {@link DatabaseMetaData} object to query the database and list all existing tables.</p><p><i><b>Important note:</b> If schemas are not supported by this connection but a schema name is even though provided in parameter, the table name will be prefixed by the schema name. The research will then be done with NULL as schema name and this prefixed table name. </i></p> <p><i>Note: Test on the schema name is done considering the case sensitivity indicated by the translator (see  {@link JDBCTranslator#isCaseSensitive(IdentifierField)}). </i></p> <p><i>Note: This function is used by   {@link #addUploadedTable(TAPTable,TableIterator)} and {@link #dropUploadedTable(TAPTable)}. </i></p>
 * @param schemaName	DB name of the schema in which the table to search is. <i>If NULL, the table is expected in any schema but ONLY one MUST exist.</i>
 * @param tableName		DB name of the table to search.
 * @param dbMeta		Metadata about the database, and mainly the list of all existing tables.
 * @return	<i>true</i> if the specified table exists, <i>false</i> otherwise.
 * @throws SQLException	If any error occurs while interrogating the database about existing tables.
 */
protected boolean isTableExisting(String schemaName,String tableName,final DatabaseMetaData dbMeta) throws DBException, SQLException {
  if (tableName == null || tableName.length() == 0)   return true;
  boolean schemaCaseSensitive=translator.isCaseSensitive(IdentifierField.SCHEMA);
  boolean tableCaseSensitive=translator.isCaseSensitive(IdentifierField.TABLE);
  ResultSet rs=null;
  try {
    if (supportsSchema) {
      String schemaPattern=schemaCaseSensitive ? schemaName : null;
      String tablePattern=tableCaseSensitive ? tableName : null;
      rs=dbMeta.getTables(null,schemaPattern,tablePattern,null);
    }
 else {
      String tablePattern=tableCaseSensitive ? tableName : null;
      rs=dbMeta.getTables(null,null,tablePattern,null);
    }
    int cnt=0;
    while (rs.next()) {
      String rsSchema=nullifyIfNeeded(rs.getString(2));
      String rsTable=rs.getString(3);
      if (!supportsSchema || schemaName == null || equals(rsSchema,schemaName,schemaCaseSensitive)) {
        if (equals(rsTable,tableName,tableCaseSensitive))         cnt++;
      }
    }
    if (cnt > 1) {
      if (logger != null)       logger.logDB(LogLevel.ERROR,this,"String_Node_Str","String_Node_Str" + schemaName + "String_Node_Str"+ schemaCaseSensitive+ "String_Node_Str"+ tableName+ "String_Node_Str"+ tableCaseSensitive+ "String_Node_Str",null);
      throw new DBException("String_Node_Str" + schemaName + "String_Node_Str"+ schemaCaseSensitive+ "String_Node_Str"+ tableName+ "String_Node_Str"+ tableCaseSensitive+ "String_Node_Str");
    }
    return cnt == 1;
  }
  finally {
    close(rs);
  }
}

Fixed version (ground truth):
/** 
 * <p>Tell whether the specified table exists in the database. To do so, it is using the given   {@link DatabaseMetaData} object to query the database and list all existing tables.</p><p><i><b>Important note:</b> If schemas are not supported by this connection but a schema name is even though provided in parameter, the table name will be prefixed by the schema name. The research will then be done with NULL as schema name and this prefixed table name. </i></p> <p><i>Note: Test on the schema name is done considering the case sensitivity indicated by the translator (see  {@link JDBCTranslator#isCaseSensitive(IdentifierField)}). </i></p> <p><i>Note: This function is used by   {@link #addUploadedTable(TAPTable,TableIterator)} and {@link #dropUploadedTable(TAPTable)}. </i></p>
 * @param schemaName	DB name of the schema in which the table to search is. <i>If NULL, the table is expected in any schema but ONLY one MUST exist.</i>
 * @param tableName		DB name of the table to search.
 * @param dbMeta		Metadata about the database, and mainly the list of all existing tables.
 * @return	<i>true</i> if the specified table exists, <i>false</i> otherwise.
 * @throws SQLException	If any error occurs while interrogating the database about existing tables.
 */
protected boolean isTableExisting(String schemaName,String tableName,final DatabaseMetaData dbMeta) throws DBException, SQLException {
  if (tableName == null || tableName.length() == 0)   return true;
  boolean schemaCaseSensitive=translator.isCaseSensitive(IdentifierField.SCHEMA);
  boolean tableCaseSensitive=translator.isCaseSensitive(IdentifierField.TABLE);
  ResultSet rs=null;
  try {
    if (supportsSchema) {
      String schemaPattern=schemaCaseSensitive ? schemaName : null;
      String tablePattern=tableCaseSensitive ? tableName : null;
      rs=getDBMetaTables(dbMeta,schemaPattern,tablePattern);
    }
 else {
      String tablePattern=tableCaseSensitive ? tableName : null;
      rs=getDBMetaTables(dbMeta,null,tablePattern);
    }
    int cnt=0;
    while (rs.next()) {
      String rsSchema=nullifyIfNeeded(rs.getString(getTableSchemaIndexInMetadata()));
      String rsTable=rs.getString(3);
      if (!supportsSchema || schemaName == null || equals(rsSchema,schemaName,schemaCaseSensitive)) {
        if (equals(rsTable,tableName,tableCaseSensitive))         cnt++;
      }
    }
    if (cnt > 1) {
      if (logger != null)       logger.logDB(LogLevel.ERROR,this,"String_Node_Str","String_Node_Str" + schemaName + "String_Node_Str"+ schemaCaseSensitive+ "String_Node_Str"+ tableName+ "String_Node_Str"+ tableCaseSensitive+ "String_Node_Str",null);
      throw new DBException("String_Node_Str" + schemaName + "String_Node_Str"+ schemaCaseSensitive+ "String_Node_Str"+ tableName+ "String_Node_Str"+ tableCaseSensitive+ "String_Node_Str");
    }
    return cnt == 1;
  }
  finally {
    close(rs);
  }
}