Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-66

[beanutils] MethodUtils.getAccessibleMethod does not work for enums

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • None
    • 1.9.5
    • Bean / Property Utils
    • None
    • Operating System: other
      Platform: Other

    • 39271

    Description

      I dont know if this is supposed to work or not, but it would be nice if
      MethodUtils.getAccessibleMethod correctly detected accessible enum methods. I
      am in the most recent production beanutils.jar (1.7.0).

      I have an enum like this in its own file:

      public enum DataEditDataType {

      /** string data type */
      STRING {
      @Override
      public String getValueName()

      { return "string"; }

      }, ...

      Then I am getting the property descriptor ok

      PropertyDescriptor propertyDescriptor = PropertyUtils.getPropertyDescriptor
      (DataEditDataType.STRING, "valueName");

      Then the method is fine

      Method method = propertyDescriptor.getReadMethod();

      But then it is seen as not accessible

      Method method = MethodUtils.getAccessibleMethod(method);

      Which return null

      The problem is line 415 of MethodUtils

      // If the declaring class is public, we are done
      Class clazz = method.getDeclaringClass();
      if (Modifier.isPublic(clazz.getModifiers()))

      { return (method); }

      For some reason, Modifer.isPrivate(clazz.getModifiers()) returns true (since
      STRING is a subclass of the DataEditDataType enum. but this is an enum
      (DataEditDataType) which is publicly available??? There could be a line here
      to see if it is an enum, then if the superclass is public in which case it is
      ok? Something like this

      if (Enum.class.isAssignableFrom(clazz) && Modifier.isPublic(clazz.getSuperclass
      ().getModifiers()) {
      return method;
      }

      That would work for me, but not sure if it would work in all cases or break
      something else or if there is another workaround I can do for my enum code.

      Thanks!
      Chris

      Attachments

        Activity

          People

            Unassigned Unassigned
            mchyzer@yahoo.com Chris
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: