|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Possible bug or strange behavior
Hi
This is the first time I'm writing to a list, so I'm not sure whether this should be sent to DevList or UserList. Sorry if I'm sending this to the wrong list. I'm using 1.7.0 version of commons-beanutils. The possible bug (or issue) I've found is in lines 416 to 418 of class MethodUtils when I'm evaluating an Enum's constant-specific method, which overrides an abstract one. Those lines are the following: 415: // If the declaring class is public, we are done 416: Class clazz = method.getDeclaringClass(); 417: if (Modifier.isPublic(clazz.getModifiers())) { 418: return (method); 419: } Since every constant of the Enum is compiled as a separate anonymous class extending the Enum, evaluating its modifiers doesn't return public, which causes the above return to be skipped. My question is: should the above code be modified to consider that particular case? Because the method is actually public and it's declaring class (the constant, actually) too. Here I show the code for testing this behavior: The enum: public enum SomeEnum { CNSTANT1 { public String getLabel() { return "a"; } }, CNSTANT2 { public String getLabel() { return "b"; } }; public abstract String getLabel(); } The test class: public class TestEnum { public static void main(String[] args) { SomeEnum a = SomeEnum.CNSTANT1; Method[] methods = a.getClass().getMethods(); System.out.println(a.getClass()); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; System.out.println(method.getName() + " - " + evaluateMethod(method)); } } private static boolean evaluateMethod(Method method) { return Modifier.isPublic(method.getDeclaringClass().getMo difiers()); } |
|
#2
|
|||
|
|||
|
Possible bug or strange behavior
Hi
This is the first time I'm writing to a list, so I'm not sure whether this should be sent to DevList or UserList. Sorry if I'm sending this to the wrong list. I'm using 1.7.0 version of commons-beanutils. The possible bug (or issue) I've found is in lines 416 to 418 of class MethodUtils when I'm evaluating an Enum's constant-specific method, which overrides an abstract one. Those lines are the following: 415: // If the declaring class is public, we are done 416: Class clazz = method.getDeclaringClass(); 417: if (Modifier.isPublic(clazz.getModifiers())) { 418: return (method); 419: } Since every constant of the Enum is compiled as a separate anonymous class extending the Enum, evaluating its modifiers doesn't return public, which causes the above return to be skipped. My question is: should the above code be modified to consider that particular case? Because the method is actually public and it's declaring class (the constant, actually) too. Here I show the code for testing this behavior: The enum: public enum SomeEnum { CNSTANT1 { public String getLabel() { return "a"; } }, CNSTANT2 { public String getLabel() { return "b"; } }; public abstract String getLabel(); } The test class: public class TestEnum { public static void main(String[] args) { SomeEnum a = SomeEnum.CNSTANT1; Method[] methods = a.getClass().getMethods(); System.out.println(a.getClass()); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; System.out.println(method.getName() + " - " + evaluateMethod(method)); } } private static boolean evaluateMethod(Method method) { return Modifier.isPublic(method.getDeclaringClass().getMo difiers()); } |
![]() |
| Viewing: Web Development Archives > Mailing Lists > Apache > Possible bug or strange behavior |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|