提交 7b6b5a2e 编写于 作者: T twalthr 提交者: Robert Metzger

Fixes a bug where Thread.currentThread().getContextClassLoader() does not...

Fixes a bug where Thread.currentThread().getContextClassLoader() does not return the user code class loader within object deserialization.
上级 ff69b1bb
...@@ -72,6 +72,8 @@ public class WordCount { ...@@ -72,6 +72,8 @@ public class WordCount {
// Set up Hadoop Output Format // Set up Hadoop Output Format
HadoopOutputFormat<Text, IntWritable> hadoopOutputFormat = new HadoopOutputFormat<Text, IntWritable>(new TextOutputFormat<Text, IntWritable>(), job); HadoopOutputFormat<Text, IntWritable> hadoopOutputFormat = new HadoopOutputFormat<Text, IntWritable>(new TextOutputFormat<Text, IntWritable>(), job);
hadoopOutputFormat.getConfiguration().set("mapreduce.output.textoutputformat.separator", " "); hadoopOutputFormat.getConfiguration().set("mapreduce.output.textoutputformat.separator", " ");
hadoopOutputFormat.getConfiguration().set("mapred.textoutputformat.separator", " "); // set the value for both, since this test
// is being executed with both types (hadoop1 and hadoop2 profile)
TextOutputFormat.setOutputPath(job, new Path(outputPath)); TextOutputFormat.setOutputPath(job, new Path(outputPath));
// Output & Execute // Output & Execute
......
...@@ -234,10 +234,13 @@ public class InstantiationUtil { ...@@ -234,10 +234,13 @@ public class InstantiationUtil {
public static Object deserializeObject(byte[] bytes, ClassLoader cl) throws IOException, ClassNotFoundException { public static Object deserializeObject(byte[] bytes, ClassLoader cl) throws IOException, ClassNotFoundException {
ObjectInputStream oois = null; ObjectInputStream oois = null;
final ClassLoader old = Thread.currentThread().getContextClassLoader();
try { try {
Thread.currentThread().setContextClassLoader(cl);
oois = new ClassLoaderObjectInputStream(new ByteArrayInputStream(bytes), cl); oois = new ClassLoaderObjectInputStream(new ByteArrayInputStream(bytes), cl);
return oois.readObject(); return oois.readObject();
} finally { } finally {
Thread.currentThread().setContextClassLoader(old);
if (oois != null) { if (oois != null) {
oois.close(); oois.close();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册