Owen,

I would like to fix this but since I am new to Hadoop I am not sure how I
can get instance of Configuration within getKey() method in
WritableComparator class.

The method newKey() is as follows:

  public WritableComparable newKey() {
    try {
      return (WritableComparable)keyClass.newInstance();  // <- line #73
    } catch (InstantiationException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }

I would like to use ReflectionUtils according to your suggestion:

  public WritableComparable newKey() {
    try {
      return
(WritableComparable)ReflectionUtils.newInstance(keyClass,null);  // <-
changed line #73
    } catch (InstantiationException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }

The second argument should be Configuration but looking into ReflectionUtils
implementation it should also work with null (should not directly throw any
exception). But I am not sure if it is recommended.

Anyway, do you want me to create a new JIRA ticket?

Regards,
Lukas

On Wed, Feb 20, 2008 at 5:33 PM, Owen O'Malley <[EMAIL PROTECTED]> wrote:

>
> 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
>



-- 
http://blog.lukas-vlcek.com/

Reply via email to