Repository: hive
Updated Branches:
  refs/heads/master eb40ea57e -> 0a81e1ec3


HIVE-19075: Fix NPE when trying to drop or get DB with null name (Marta 
Kuczora, via Peter Vary)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/0a81e1ec
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/0a81e1ec
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/0a81e1ec

Branch: refs/heads/master
Commit: 0a81e1ec309673007bc3e1a37cf88c92edfc285c
Parents: eb40ea5
Author: Marta Kuczora <kuczo...@cloudera.com>
Authored: Fri Apr 6 11:37:49 2018 +0200
Committer: Peter Vary <pv...@cloudera.com>
Committed: Fri Apr 6 11:37:49 2018 +0200

----------------------------------------------------------------------
 .../hadoop/hive/metastore/HiveMetaStore.java    |  6 ++++
 .../hive/metastore/client/TestDatabases.java    | 37 ++++----------------
 2 files changed, 12 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/0a81e1ec/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
----------------------------------------------------------------------
diff --git 
a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
 
b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
index 8539fea..450da4f 100644
--- 
a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ 
b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -1290,6 +1290,9 @@ public class HiveMetaStore extends ThriftHiveMetastore {
     @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 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       List<Path> tablePaths = new ArrayList<>();
       List<Path> partitionPaths = new ArrayList<>();
       Map<String, String> transactionalListenerResponses = 
Collections.emptyMap();
+      if (name == null) {
+        throw new MetaException("Database name cannot be null.");
+      }
       try {
         ms.openTransaction();
         db = ms.getDatabase(catName, name);

http://git-wip-us.apache.org/repos/asf/hive/blob/0a81e1ec/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java
----------------------------------------------------------------------
diff --git 
a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java
 
b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java
index 24e3c56..d558de6 100644
--- 
a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java
+++ 
b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java
@@ -40,7 +40,6 @@ import 
org.apache.hadoop.hive.metastore.client.builder.TableBuilder;
 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 class TestDatabases extends MetaStoreClientTest {
     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 class TestDatabases extends MetaStoreClientTest {
     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

Reply via email to