You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Lukasz Lenart (JIRA)" <ji...@apache.org> on 2015/12/10 15:35:11 UTC
[jira] [Updated] (OGNL-158) Statics within Enums causing
IllegalArgumentExceptions.
[ https://issues.apache.org/jira/browse/OGNL-158?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lukasz Lenart updated OGNL-158:
-------------------------------
Fix Version/s: 3.1.2
> Statics within Enums causing IllegalArgumentExceptions.
> -------------------------------------------------------
>
> Key: OGNL-158
> URL: https://issues.apache.org/jira/browse/OGNL-158
> Project: Commons OGNL
> Issue Type: Bug
> Components: Core Runtime
> Affects Versions: 2.7.3
> Environment: N/A
> Reporter: Kyle Lomeli
> Assignee: Jesse Kuhnert
> Fix For: 3.1.2
>
>
> 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.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)