You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Kukosa, Tomas" <to...@siemens-enterprise.com> on 2012/07/04 09:42:26 UTC

[jexl] Unexpected Integer -> Byte conversion

Hello,

if I pass variable containing Integer value to the script with parameters the parameter inside the script gets the value as Byte.
It is not a problem e.g. for arithmetic expressions.
The problem occurs if I try to access map wit this numeric value. The map has numeric keys as Integer and accessing with Byte fails.

Is there any better way how to solve it than using MY_MAP[1*idx] in all places where I could expect that idx could be a Byte value?

(using jexl 2.1.1)

Regards,
  Tomas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [jexl] Unexpected Integer -> Byte conversion

Posted by henrib <he...@apache.org>.
Hi Tomas;
Good and clear report; found the bug in 2.1.x, not in 3.0, created JEXL-136,
fixed it, committed in branch 2.0 (for 2.1.2) and added test to trunk for
good measure (for 3.0).

The published 3.0 snapshot does *not* have this bug; you can find it here:
https://repository.apache.org/content/groups/snapshots/org/apache/commons/commons-jexl3/3.0-SNAPSHOT/

I'd recommend using maven to use the snapshot repo. 
Hope this helps,
Cheers
Henrib

--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-Unexpected-Integer-Byte-conversion-tp4635879p4636056.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [jexl] Unexpected Integer -> Byte conversion

Posted by "Kukosa, Tomas" <to...@siemens-enterprise.com>.
Hi Henrib,

please try it with code below.

The result is:
EXPR01 result=null ## NOT OK
EXPR02 result=22 ## OK

Is anywhere available built 3.0 SNAPSHOT jar file or do I need to build it myself from SVN repository?

Best regards,
  Tomas

--------------------------
public class Test01 {

	private final static String SCR_INIT = "$TAB = { 1:11, 2:22, 3:33}; IDX=2;";
	private final static String[] SCR_FN01_PARS = { "idx" };
	private final static String SCR_FN01 = "var x = $TAB[idx]; return x;";
	private final static String SCR_EXPR01 = "fn01(IDX)";
	private final static String SCR_FN02 = "var x = $TAB[1*idx]; return x;";
	private final static String SCR_EXPR02 = "fn02(IDX)";
	
	public static void main(String[] args) {
		JexlEngine jexl = new JexlEngine();
		JexlContext jc = new MapContext();
		Script script;
		Expression expr;
		Object result;

		script = jexl.createScript(SCR_FN01, SCR_FN01_PARS);
		jc.set("fn01", script);
		script = jexl.createScript(SCR_FN02, SCR_FN01_PARS);
		jc.set("fn02", script);

		script = jexl.createScript(SCR_INIT);
		script.execute(jc);
		
		expr = jexl.createExpression(SCR_EXPR01);
		result = expr.evaluate(jc);
		System.out.print(String.format("EXPR01 result=%s\n", result));
		
		expr = jexl.createExpression(SCR_EXPR02);
		result = expr.evaluate(jc);
		System.out.print(String.format("EXPR02 result=%s\n", result));
		
	}
}

-----Original Message-----
From: henrib [mailto:henrib@apache.org] 
Sent: Thursday, July 05, 2012 11:33 AM
To: user@commons.apache.org
Subject: Re: [jexl] Unexpected Integer -> Byte conversion

Hi Tomas,
Your previous issue (JEXL-135) has been solved in the trunk (2.1.2 and 3.0).
Not sure about this one, I can't reproduce it on the trunk using the
following test:

{code}

    public void test135() throws Exception {
        JexlEngine jexl = new JexlEngine();
        JexlContext jc = new MapContext();
        Script script;
        Object result;
        Map<Integer, Object> foo = new HashMap<Integer, Object>();
        foo.put(3, 42);
        jc.set("state", foo);

        script = jexl.createScript("var y = state[3]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 3);
        script = jexl.createScript("var y = state[a]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 2);
        script = jexl.createScript("var y = state[a + 1]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 2);
        jc.set("b", 1);
        script = jexl.createScript("var y = state[a + b]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[3]; y", "state");
        result = script.execute(null, foo, 3);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a]; y", "state", "a");
        result = script.execute(null, foo, 3);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a + 1]; y", "state", "a");
        result = script.execute(null, foo, 2);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a + b]; y", "state", "a",
"b");
        result = script.execute(null, foo, 2, 1);
        assertEquals(42, result);
    }
{code}
Let me know what I'm missing.
Regards
Henrib

PS: If you are starting/evaluating to use JEXL and if you can, I'd suggest
you use the 3.0 SNAPSHOT (published a new one today).


--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-Unexpected-Integer-Byte-conversion-tp4635879p4635902.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [jexl] Unexpected Integer -> Byte conversion

Posted by henrib <he...@apache.org>.
Hi Tomas,
Your previous issue (JEXL-135) has been solved in the trunk (2.1.2 and 3.0).
Not sure about this one, I can't reproduce it on the trunk using the
following test:

{code}

    public void test135() throws Exception {
        JexlEngine jexl = new JexlEngine();
        JexlContext jc = new MapContext();
        Script script;
        Object result;
        Map<Integer, Object> foo = new HashMap<Integer, Object>();
        foo.put(3, 42);
        jc.set("state", foo);

        script = jexl.createScript("var y = state[3]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 3);
        script = jexl.createScript("var y = state[a]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 2);
        script = jexl.createScript("var y = state[a + 1]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 2);
        jc.set("b", 1);
        script = jexl.createScript("var y = state[a + b]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[3]; y", "state");
        result = script.execute(null, foo, 3);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a]; y", "state", "a");
        result = script.execute(null, foo, 3);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a + 1]; y", "state", "a");
        result = script.execute(null, foo, 2);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a + b]; y", "state", "a",
"b");
        result = script.execute(null, foo, 2, 1);
        assertEquals(42, result);
    }
{code}
Let me know what I'm missing.
Regards
Henrib

PS: If you are starting/evaluating to use JEXL and if you can, I'd suggest
you use the 3.0 SNAPSHOT (published a new one today).


--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-Unexpected-Integer-Byte-conversion-tp4635879p4635902.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org