Commons BeanUtils
  1. Commons BeanUtils
  2. BEANUTILS-298

MethodUtils.getAccessibleMethod(Method method) could not find right public method

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.0, 1.8.0-BETA
    • Fix Version/s: 1.8.0
    • Component/s: Bean / Property Utils
    • Labels:
      None
    • Environment:

      Java 1.5, Windows XP

      Description

      Let assume follows:

      public interface IX {
      getName();
      }

      class BaseX {
      public getName();
      }

      class ImplX extends BaseX implements IX {
      }

      For some reason I do not want that BaseX implements IX, but if we have a bean of type ImplX we can call getName().

      PropertyUtils.getProperty(beanOfTypeBaseX, "name") could not get the value, because the method MethodUtils.getAccessibleMethod(Method method) looks up only throunght supercalsses and interfaces of implementing class but not the subclasses and interfaces that they implement!

      So PropertyUtils.getProperty(beanOfTypeBaseX, "name") throws an Exception that the method is not accessible, but at the same time I can call beanOfTypeBaseX.getName()

        Activity

        Hide
        Niall Pemberton added a comment -

        Thanks for reporting this. Unfortunately in this scenario there is no fix for MethodUtils.getAccessibleMethod(Method) - since it can only check superclasses/interfaces of the class returned by Method.getDeclaringClass(). In your scenario the declaring class is BaseX and therefore the interface IX is not available. So I have added a new MethodUtils.getAccessibleMethod(Class, Method) method which can be used instead. I have changed PropertyUtils to use this new method so that now your PropertyUtils.getProperty(beanOfTypeBaseX, "name") works:

        http://svn.apache.org/viewvc?view=rev&revision=644143

        Closing this as fixed.

        Show
        Niall Pemberton added a comment - Thanks for reporting this. Unfortunately in this scenario there is no fix for MethodUtils.getAccessibleMethod(Method) - since it can only check superclasses/interfaces of the class returned by Method.getDeclaringClass(). In your scenario the declaring class is BaseX and therefore the interface IX is not available. So I have added a new MethodUtils.getAccessibleMethod(Class, Method) method which can be used instead. I have changed PropertyUtils to use this new method so that now your PropertyUtils.getProperty(beanOfTypeBaseX, "name") works: http://svn.apache.org/viewvc?view=rev&revision=644143 Closing this as fixed.

          People

          • Assignee:
            Niall Pemberton
            Reporter:
            Roman Mukhin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development