diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 8539fea..450da4f 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -1290,6 +1290,9 @@ public Database get_database(final String name) throws NoSuchObjectException, Me @Override public Database get_database_core(String catName, final String name) throws NoSuchObjectException, MetaException { Database db = null; + if (name == null) { + throw new MetaException("Database name cannot be null."); + } try { db = getMS().getDatabase(catName, name); } catch (MetaException | NoSuchObjectException e) { @@ -1364,6 +1367,9 @@ private void drop_database_core(RawStore ms, String catName, List tablePaths = new ArrayList<>(); List partitionPaths = new ArrayList<>(); Map transactionalListenerResponses = Collections.emptyMap(); + if (name == null) { + throw new MetaException("Database name cannot be null."); + } try { ms.openTransaction(); db = ms.getDatabase(catName, name); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java index 24e3c56..d558de6 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java @@ -40,7 +40,6 @@ import org.apache.hadoop.hive.metastore.minihms.AbstractMetaStoreService; import org.apache.hadoop.hive.metastore.utils.SecurityUtils; import org.apache.thrift.TException; -import org.apache.thrift.transport.TTransportException; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -227,18 +226,10 @@ public void testGetDatabaseNoSuchDatabase() throws Exception { client.getDatabase("no_such_database"); } - @Test + @Test(expected = MetaException.class) public void testGetDatabaseNullName() throws Exception { // Missing database name in the query - try { - client.getDatabase(null); - // TODO: Should have a check on the server side. - Assert.fail("Expected a NullPointerException or TTransportException to be thrown"); - } catch (NullPointerException exception) { - // Expected exception - Embedded MetaStore - } catch (TTransportException exception) { - // Expected exception - Remote MetaStore - } + client.getDatabase(null); } @Test(expected = NoSuchObjectException.class) @@ -246,32 +237,16 @@ public void testDropDatabaseNoSuchDatabase() throws Exception { client.dropDatabase("no_such_database"); } - @Test + @Test(expected = MetaException.class) public void testDropDatabaseNullName() throws Exception { // Missing database in the query - try { - client.dropDatabase(null); - // TODO: Should be checked on server side - Assert.fail("Expected an NullPointerException or TTransportException to be thrown"); - } catch (NullPointerException exception) { - // Expected exception - Embedded MetaStore - } catch (TTransportException exception) { - // Expected exception - Remote MetaStore - } + client.dropDatabase(null); } - @Test + @Test(expected = MetaException.class) public void testDropDatabaseDefaultDatabase() throws Exception { // Check if it is possible to drop default database - try { - client.dropDatabase(DEFAULT_DATABASE); - // TODO: Should be checked on server side - Assert.fail("Expected an MetaException or TTransportException to be thrown"); - } catch (MetaException exception) { - // Expected exception - Embedded MetaStore - } catch (TTransportException exception) { - // Expected exception - Remote MetaStore - } + client.dropDatabase(DEFAULT_DATABASE); } @Test