Index: serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java =================================================================== --- serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java (revision 1127457) +++ serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java (working copy) @@ -30,6 +30,8 @@ import org.apache.thrift.protocol.TMap; import org.apache.thrift.protocol.TStruct; import org.apache.thrift.transport.TMemoryBuffer; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; /** * TestTCTLSeparatedProtocol. @@ -474,4 +476,36 @@ assertTrue(ret1 == 0); } + public void testShouldThrowRunTimeExceptionIfUnableToInitializeTokenizer() throws Exception { + TCTLSeparatedProtocol separatedProtocol = new TCTLSeparatedProtocol(new TTransport() { + @Override + public void close() { + } + + @Override + public boolean isOpen() { + return false; + } + + @Override + public void open() throws TTransportException { + } + + @Override + public int read(byte[] buf, int off, int len) throws TTransportException { + throw new TTransportException(); + } + + @Override + public void write(byte[] buf, int off, int len) throws TTransportException { + } + }); + separatedProtocol.initialize(null, new Properties()); + try { + separatedProtocol.readStructBegin(); + fail("Runtime Exception is expected if the intialization of tokenizer failed."); + } catch (Exception e) { + assertTrue(e.getCause() instanceof TTransportException); + } + } } Index: serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java (revision 1127457) +++ serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java (working copy) @@ -219,10 +219,17 @@ this.trans = trans; this.separator = separator; buf = new byte[buffer_length]; + } + + private void initialize() { // do not fill tokenizer until user requests since filling it could read // in data // not meant for this instantiation. - fillTokenizer(); + try { + fillTokenizer(); + } catch (Exception e) { + LOG.warn("Unable to initialize tokenizer", e); + } } private boolean fillTokenizer() { @@ -244,9 +251,8 @@ tokenizer = new StringTokenizer("", separator, true); return false; } - e.printStackTrace(); tokenizer = null; - return false; + throw new RuntimeException(e); } return true; } @@ -364,6 +370,7 @@ nullText = new Text(nullString); transportTokenizer = new SimpleTransportTokenizer(innerTransport, rowSeparator, bufferSize); + transportTokenizer.initialize(); } /**