diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java index dffeb34f44..e71f24cb0b 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java @@ -28,12 +28,14 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +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; @@ -71,6 +73,7 @@ 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; @@ -1554,6 +1557,61 @@ public void testColumnStatistics() throws Throwable { } } + 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 cols = new ArrayList(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"; diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java index 38dc4062f8..40e408cc31 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java @@ -393,7 +393,7 @@ static public Deserializer getDeserializer(Configuration conf, 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()); @@ -436,7 +436,7 @@ static public Deserializer getDeserializer(Configuration conf, 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());