commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (OGNL-158) Statics within Enums causing IllegalArgumentExceptions.
Date Thu, 10 Dec 2015 14:35:11 GMT

    [ https://issues.apache.org/jira/browse/OGNL-158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15051039#comment-15051039
] 

Lukasz Lenart commented on OGNL-158:
------------------------------------

Sorry, missed that out :(

> 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)

Mime
View raw message