diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java index cc1e517eaa586..9e0674b942514 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java @@ -195,23 +195,23 @@ public void write(DataOutput out) throws IOException { @Override public void readFields(DataInput in) throws IOException { - + // Get the number of "unknown" classes - newClasses = in.readByte(); - + + // Get the class loader of the current thread because + // Class.forName does not have the job jar in its path + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + // Then read in the class names and add them to our tables - for (int i = 0; i < newClasses; i++) { byte id = in.readByte(); String className = in.readUTF(); try { - addToMap(Class.forName(className), id); - + addToMap(classLoader.loadClass(className), id); } catch (ClassNotFoundException e) { - throw new IOException("can't find class: " + className + " because "+ - e.getMessage()); + throw new IOException(e); } } - } + } }