Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.7.3
-
None
-
N/A
Description
Class ognl.OgnlRuntime#getStaticField(OgnlContext, String, String) cannot access static constants within Enum classes.
Consider the following Enum:
public class Enum MyEnum {
VALUE_1,
VALUE_2,
VALUE_3;
public static final MyEnum[] FIRST_TWO =
{MyEnum.VALUE_1, MyEnum.VALUE_2};
}
I am trying to access the static constant by using the following ognl expression: @my.company.MyEnum@FIRST_TWO.
We are getting an IllegalArgumentException. The cause is the following if condition:
if (fieldName.equals("class"))
{ return c; }
else if (OgnlRuntime.isJdk15() && c.isEnum())
{ return Enum.valueOf(c, fieldName); }
else
{ Field f = c.getField(fieldName); if (!Modifier.isStatic(f.getModifiers())) throw new OgnlException("Field " + fieldName + " of class " + className + " is not static"); return f.get(null); }The 'else if' block assumes that if the class is an Enum, then all fields within that class are enums. This used to work on an old (and we mean OLD) version of ognl we were using. We recently upgraded to 2.7.3 and encountered this problem.
Attachments
Issue Links
- is duplicated by
-
WW-4479 Ognl can't access static field on enum
- Closed