Uploaded image for project: 'Commons OGNL (Dormant)'
  1. Commons OGNL (Dormant)
  2. OGNL-158

Statics within Enums causing IllegalArgumentExceptions.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.7.3
    • 3.1.2
    • Core Runtime
    • 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

          Activity

            People

              jkuhnert Jesse Kuhnert
              kyle Kyle Lomeli
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: