You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (JIRA)" <ji...@apache.org> on 2016/03/22 16:25:25 UTC

[jira] [Commented] (JEXL-192) Invalid return type when expected result is null

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

Henri Biestro commented on JEXL-192:
------------------------------------

I fail reproducing your issue on the trunk with the current information; can you pinpoint what I must be missing ?
My test code is this:
{code}
    public static class C192 {
        public C192() {}

        public static Integer callme(Integer n) {
            if (n == null) {
                return 0;
            } else {
                return n >= 0? 42 : -42;
            }
        }
    }

    @Test
    public void test192() throws Exception {
        JexlContext jc = new MapContext();
        jc.set("x.y.z",  C192.class);
        JexlEngine jexl = new JexlBuilder().create();
        JexlExpression js0 = jexl.createExpression("x.y.z.callme(t)");
        jc.set("t", null);
        Assert.assertEquals(0, js0.evaluate(jc));
        jc.set("t", 10);
        Assert.assertEquals(42, js0.evaluate(jc));
        jc.set("t", -10);
        Assert.assertEquals(-42, js0.evaluate(jc));
        jc.set("t", null);
        Assert.assertEquals(0, js0.evaluate(jc));
    }
{code}

> Invalid return type when expected result is null
> ------------------------------------------------
>
>                 Key: JEXL-192
>                 URL: https://issues.apache.org/jira/browse/JEXL-192
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: Constantin Mitocaru
>            Assignee: Henri Biestro
>            Priority: Blocker
>
> In jexl2 this code correctly outputs the line:
> {code}
> null
> {code}
> {code:java}
>         JexlEngine jexl = new JexlEngine();
>         Record r = new Record();
>         r.setHeader(new RecordHeader());
>         JexlContext jc = new MapContext();
>         jc.set("r", r );
>         jc.set("com.s.objects.record.RecordUtils", com.s.objects.record.RecordUtils.class );
>         Expression e = jexl.createExpression( "com.s.objects.record.RecordUtils.getHeaderAgeOrResolveItFromDOB(r)" );
>         System.out.println( e.evaluate(jc) );        
> {code}
> The signature of the method getHeaderAgeOrResolveItFromDOB() is:
> {code:java}
>         public static Integer getHeaderAgeOrResolveItFromDOB( final Record rec ) {
>         ...
>         }
> {code}
> But in jexl3 this code produces:
> {code}
> 	class com.s.objects.record.RecordUtils
> {code}
> {code:java}
>         JexlEngine jexl = new JexlBuilder().create();
>         Record r = new Record();
>         r.setHeader(new RecordHeader());
>         JexlContext jc = new MapContext();
>         jc.set("r", r );
>         jc.set("com.s.objects.record.RecordUtils", com.s.objects.record.RecordUtils.class );
>         JexlExpression e = jexl.createExpression( "com.s.objects.record.RecordUtils.getHeaderAgeOrResolveItFromDOB(r)" );
>         System.out.println( e.evaluate(jc) );        
> {code}
> So it returns the class of the utility rather than the value null! For non null values it returns the proper type (Integer);
> I think jexl3 version 3.0 was not really ready for prime time.
> I really screwed up my project upgrading to 3.0.
> When do you guys anticipate to release 3.1?
> Is there a way to work with a snapshot after this fix?



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