commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Constantin Mitocaru (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (JEXL-191) Jexl3 unsolvable property exception when using enum
Date Thu, 17 Mar 2016 13:37:33 GMT

     [ https://issues.apache.org/jira/browse/JEXL-191?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Constantin Mitocaru updated JEXL-191:
-------------------------------------
    Environment:     (was: This code used to work under jexl2
{code:java}
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) );
}
{code}

but under jexl3 it throws an exception:

{code:java}
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) );
}
{code}

The exception is:

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

Temporary workaround is using the valueOf method:

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

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)

> Jexl3 unsolvable property exception when using enum
> ---------------------------------------------------
>
>                 Key: JEXL-191
>                 URL: https://issues.apache.org/jira/browse/JEXL-191
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: Constantin Mitocaru
>            Priority: Critical
>
> I first logged a question on stack overflow:
> http://stackoverflow.com/questions/36061706/jexl3-unsolvable-property-exception-when-using-enum
> 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'
> I made it to work 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



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message