Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-191

Jexl3 unsolvable property exception when using enum

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 3.0
    • Fix Version/s: 3.1
    • Labels:
      None

      Description

      This code used to work under jexl2

      public enum Gender { MALE, FEMALE};
      
      public static void main( String[] args ) throws ClassNotFoundException {
          JexlEngine jexl = new JexlEngine();
          Record r = new Record();
          r.setHeader(new RecordHeader());
          JexlContext jc = new MapContext();
          jc.set("r", r );
          jc.set("com.sytrue.objects.Gender", Gender.class );
          Expression e = jexl.createExpression( "r.header.gender=com.sytrue.objects.Gender.FEMALE" );
          System.out.println( e.evaluate(jc) );
      }
      

      but under jexl3 it throws an exception:

      public static void main( String[] args ) throws ClassNotFoundException {
          JexlEngine jexl = new JexlBuilder().create();
          Record r = new Record();
          r.setHeader(new RecordHeader());
          JexlContext jc = new MapContext();
          jc.set("r", r );
          jc.set("com.sytrue.objects.Gender", Gender.class );
          JexlExpression e = jexl.createExpression( "r.header.gender=com.sytrue.objects.Gender.FEMALE" );
          System.out.println( e.evaluate(jc) );
      }
      

      The exception is:

      Exception in thread "main" org.apache.commons.jexl3.JexlException$Property: com.sytrue.objects.record.app.JexlTestApp.main@1:42 unsolvable property 'FEMALE'
      

      Temporary workaround is using the valueOf method:

      JexlExpression e = jexl.createExpression( "r.header.gender=com.sytrue.objects.Gender.valueOf('FEMALE')" );
      

      It seems that I no longer can access the enum type in jexl3.
      Is there any reason this doesn't work anymore or it is a bug

        Attachments

          Activity

            People

            • Assignee:
              henrib Henri Biestro
              Reporter:
              biliboc Constantin Mitocaru
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: