On Feb 20, 2008, at 6:23 AM, Lukas Vlcek wrote:
Hi,
WritableComparator, line# 73 (trunk version) is using Class'
newInstance()
method which can not work for singletons like NullWritable.
*SIgh* I thought I had removed all of those direct calls to
Class.newInstance. It really should be using
ReflectionUtils.newInstance, which would work. NullWritable is mostly
a singleton, but it isn't really required to be a singleton.
Should this be changed to:
/** Construct a new [EMAIL PROTECTED] WritableComparable} instance. */
public WritableComparable newKey() {
try {
if (keyClass instanceof NullWritable) return NullWritable.get
(); //
<--- this is new line
return (WritableComparable)keyClass.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
I think you mean:
if (keyClass == NullWritable.class) {
return NullWritable.get();
}
and in reality, it would be better to put that fix in
ReflectionUtils.newInstance and just call it from here.
Thanks,
Owen