Details
-
Bug
-
Status: Reopened
-
Major
-
Resolution: Unresolved
-
None
-
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()
}, ...
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()))
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