[ https://issues.apache.org/jira/browse/BEANUTILS-66?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory updated BEANUTILS-66: ------------------------------------- Fix Version/s: 1.10.1 (was: 1.10.0) > [beanutils] MethodUtils.getAccessibleMethod does not work for enums > ------------------------------------------------------------------- > > Key: BEANUTILS-66 > URL: https://issues.apache.org/jira/browse/BEANUTILS-66 > Project: Commons BeanUtils > Issue Type: Bug > Components: Bean / Property Utils > Environment: Operating System: other > Platform: Other > Reporter: Chris > Priority: Major > Fix For: 1.10.1 > > > 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 -- This message was sent by Atlassian Jira (v8.20.10#820010)