You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@click.apache.org by Bob Schellink <sa...@gmail.com> on 2008/10/20 19:12:02 UTC

ensureObjectPathNotNull changes

Hi all,

I checked in some code which changes the way in which 
ensureObjectPathNotNull looks up getter methods.

Just making sure I am not missing something obvious with this change.

The previous code looped through all the methods and checked against 
the path if a getter method matches. Here is the code:

   String getterName = ClickUtils.toGetterName(value);
   Method foundMethod = null;
   Method[] methods = object.getClass().getMethods();
   for (int i = 0; i < methods.length; i++) {
     String name = methods[i].getName();
     if (name.equals(getterName)) {
       foundMethod = methods[i];
       break;
     }
     ...
   }

The new code looks up the getter using reflection:

Method method = null;
String getterName = ClickUtils.toGetterName(value);
Class sourceClass = object.getClass();
method = sourceClass.getMethod(getterName, null);

Was there a specific reason for the previous version? Perhaps 
performance issue?

If you see any problems with this change please give a shout so we can 
fix this before 1.5.

kind regards

bob