Repository: hive
Updated Branches:
  refs/heads/master 92f764e05 -> cff4e2032


HIVE-17115: MetaStoreUtils.getDeserializer doesn't catch the 
java.lang.ClassNotFoundException (Erik.fang, reviewed by Daniel Dai)


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

Branch: refs/heads/master
Commit: cff4e2032811357af2c39cdd25a67550ab77d6b5
Parents: 92f764e
Author: Daniel Dai <da...@hortonworks.com>
Authored: Tue Aug 8 13:44:26 2017 -0700
Committer: Daniel Dai <da...@hortonworks.com>
Committed: Tue Aug 8 13:44:26 2017 -0700

----------------------------------------------------------------------
 .../hive/metastore/TestHiveMetaStore.java       | 58 ++++++++++++++++++++
 .../hadoop/hive/metastore/MetaStoreUtils.java   |  4 +-
 2 files changed, 60 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/cff4e203/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
----------------------------------------------------------------------
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
index 603e5e9..3fcf1bb 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
@@ -30,6 +30,7 @@ import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
@@ -42,6 +43,7 @@ import org.datanucleus.api.jdo.JDOPersistenceManager;
 import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.FsPermission;
@@ -83,6 +85,7 @@ import org.apache.hadoop.hive.ql.io.HiveInputFormat;
 import org.apache.hadoop.hive.ql.io.HiveOutputFormat;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.serde.serdeConstants;
+import org.apache.hadoop.hive.serde2.SerDeException;
 import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.thrift.TException;
@@ -1725,6 +1728,61 @@ public abstract class TestHiveMetaStore extends TestCase 
{
     }
   }
 
+  static class ClassNotFoundSerde extends LazySimpleSerDe {
+
+    public ClassNotFoundSerde() throws Exception {
+    }
+
+    @Override
+    public void initialize(Configuration job, Properties tbl) throws 
SerDeException {
+      super.initialize(job, tbl);
+      throw new NoClassDefFoundError();
+    }
+
+  }
+
+  public void testGetSchemaWithNoClassDefFoundError() throws Exception {
+    try {
+      String dbName = "testDb";
+      String tblName = "testTable";
+
+      client.dropTable(dbName, tblName);
+      silentDropDatabase(dbName);
+
+      Database db = new Database();
+      db.setName(dbName);
+      client.createDatabase(db);
+
+      Table tbl = new Table();
+      tbl.setDbName(dbName);
+      tbl.setTableName(tblName);
+
+      ArrayList<FieldSchema> cols = new ArrayList<FieldSchema>(1);
+      cols.add(new FieldSchema("name", serdeConstants.STRING_TYPE_NAME, ""));
+
+      StorageDescriptor sd = new StorageDescriptor();
+      tbl.setSd(sd);
+      sd.setCols(cols);
+      SerDeInfo serdeInfo = new SerDeInfo();
+      sd.setSerdeInfo(serdeInfo);
+      serdeInfo.setSerializationLib(ClassNotFoundSerde.class.getName());
+
+      client.createTable(tbl);
+
+      Boolean MetaExceptionCaught = false;
+      try {
+        client.getSchema(dbName, tblName);
+      } catch (MetaException me) {
+        MetaExceptionCaught = true;
+      }
+      assertTrue("MetaException is expected to be caught for throwing 
NoClassDefFoundError", MetaExceptionCaught);
+    } catch (Throwable e) {
+      System.err.println(StringUtils.stringifyException(e));
+      System.err.println("testGetSchemaWithNoClassDefFoundError() failed.");
+      throw e;
+    }
+  }
+
   public void testAlterTable() throws Exception {
     String dbName = "alterdb";
     String invTblName = "alter-tbl";

http://git-wip-us.apache.org/repos/asf/hive/blob/cff4e203/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
index 48602bd..c95749c 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
@@ -463,7 +463,7 @@ public class MetaStoreUtils {
       return deserializer;
     } catch (RuntimeException e) {
       throw e;
-    } catch (Exception e) {
+    } catch (Throwable e) {
       LOG.error("error in initSerDe: " + e.getClass().getName() + " "
           + e.getMessage(), e);
       throw new MetaException(e.getClass().getName() + " " + e.getMessage());
@@ -506,7 +506,7 @@ public class MetaStoreUtils {
       return deserializer;
     } catch (RuntimeException e) {
       throw e;
-    } catch (Exception e) {
+    } catch (Throwable e) {
       LOG.error("error in initSerDe: " + e.getClass().getName() + " "
           + e.getMessage(), e);
       throw new MetaException(e.getClass().getName() + " " + e.getMessage());

Reply via email to