HADOOP-12406. Fixed AbstractMapWritable.readFields to use the thread's ClassLoader to load class instead of System ClassLoader. Contributed by Nadeem Douba.
(cherry picked from commit069c6c62de
) (cherry picked from commit4041d2b49e
)
This commit is contained in:
parent
689d19575f
commit
9721735ce9
|
@ -181,20 +181,22 @@ public abstract class AbstractMapWritable implements Writable, Configurable {
|
||||||
public void readFields(DataInput in) throws IOException {
|
public void readFields(DataInput in) throws IOException {
|
||||||
|
|
||||||
// Get the number of "unknown" classes
|
// Get the number of "unknown" classes
|
||||||
|
|
||||||
newClasses = in.readByte();
|
newClasses = in.readByte();
|
||||||
|
|
||||||
// Then read in the class names and add them to our tables
|
// Use the classloader of the current thread to load classes instead of the
|
||||||
|
// system-classloader so as to support both client-only and inside-a-MR-job
|
||||||
|
// use-cases. The context-loader by default eventually falls back to the
|
||||||
|
// system one, so there should be no cases where changing this is an issue.
|
||||||
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
|
// Then read in the class names and add them to our tables
|
||||||
for (int i = 0; i < newClasses; i++) {
|
for (int i = 0; i < newClasses; i++) {
|
||||||
byte id = in.readByte();
|
byte id = in.readByte();
|
||||||
String className = in.readUTF();
|
String className = in.readUTF();
|
||||||
try {
|
try {
|
||||||
addToMap(Class.forName(className), id);
|
addToMap(classLoader.loadClass(className), id);
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new IOException("can't find class: " + className + " because "+
|
throw new IOException(e);
|
||||||
e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue