Incorrect initialization of thread local variable inside IOContext ( implementation is not threadsafe ) --------------------------------------------------------------------------------------------------------
Key: HIVE-1647 URL: https://issues.apache.org/jira/browse/HIVE-1647 Project: Hadoop Hive Issue Type: Bug Components: Server Infrastructure Affects Versions: 0.5.0 Reporter: Raman Grover Fix For: 0.3.1 Bug in org.apache.hadoop.hive.ql.io.IOContext in relation to initialization of thread local variable. public class IOContext { private static ThreadLocal<IOContext> threadLocal = new ThreadLocal<IOContext>(){ }; static { if (threadLocal.get() == null) { threadLocal.set(new IOContext()); } } In a multi-threaded environment, the thread that gets to load the class first for the JVM (assuming threads share the classloader), gets to initialize itself correctly by executing the code in the static block. Once the class is loaded, any subsequent threads would have their respective threadlocal variable as null. Since IOContext is set during initialization of HiveRecordReader, In a scenario where multiple threads get to acquire an instance of HiveRecordReader, it would result in a NPE for all but the first thread that gets to load the class in the VM. Is the above scenario of multiple threads initializing HiveRecordReader a typical one ? or we could just provide the following fix... private static ThreadLocal<IOContext> threadLocal = new ThreadLocal<IOContext>(){ protected synchronized IOContext initialValue() { return new IOContext(); } }; -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.