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/08/10 15:07:26 UTC

[jexl] empty() function crashes if called with int[]

Hi,

if the empty() function is called for variable containing int[] it causes an exception:

java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
	at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:715)
	at org.apache.commons.jexl2.parser.ASTEmptyFunction.jjtAccept(ASTEmptyFunction.java:18)
	at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1364)
	at org.apache.commons.jexl2.parser.ASTReturnStatement.jjtAccept(ASTReturnStatement.java:18)
	at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:946)
	at org.apache.commons.jexl2.parser.ASTJexlScript.jjtAccept(ASTJexlScript.java:38)
	at org.apache.commons.jexl2.Interpreter.interpret(Interpreter.java:232)
	at org.apache.commons.jexl2.ExpressionImpl.execute(ExpressionImpl.java:107)

See the example below.


BTW how an empty map could be created? The {} literal is not valid jexl syntax.

Best regards,
  Tomas

---------------------------------
public class Test04 {

	private final static String[] SCRIPTS = {
		"var x = null; return empty(x);",
		"var x = ''; return empty(x);",
		"var x = 'abc'; return empty(x);",
		"var x = 0; return empty(x);",
		"var x = 333; return empty(x);",
		"var x = []; return empty(x);",
		"var x = [1, 2]; return empty(x);",  // === ERROR ===
		"var x = ['a', 'b']; return empty(x);",
		// "var x = {}; return empty(x);",
		"var x = {1:'A', 2:'B'}; return empty(x);",
	};

	public static void main(String[] args) {
		JexlEngine jexl = new JexlEngine();
		JexlContext jc = new MapContext();
		Script script;

		for (String stext : SCRIPTS) {
			System.out.println(stext);
			script = jexl.createScript(stext);
			try {
				Object ret = script.execute(jc);
				System.out.println(ret);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}

}

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


Re: [jexl] empty() function crashes if called with int[]

Posted by henrib <he...@apache.org>.
Hi,
The empty map syntax is { : } .
May I suggest you create issues within Jira with your test cases, it might
ease getting them solved & released.
Btw, I've committed solutions for your last 2 problems in jexl(3) trunk.
Regards



--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-empty-function-crashes-if-called-with-int-tp4637895p4637908.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] empty() function crashes if called with int[]

Posted by Martin Gainty <mg...@hotmail.com>.
{}
create the HashMap first with 0 entries
http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html

Objects are not primitive types and vice versa
Initialise ints as Integer first
new Integer(intValue);

Martin Gainty 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> From: tomas.kukosa@siemens-enterprise.com
> To: user@commons.apache.org
> Subject: [jexl] empty() function crashes if called with int[]
> Date: Fri, 10 Aug 2012 13:07:26 +0000
> 
> Hi,
> 
> if the empty() function is called for variable containing int[] it causes an exception:
> 
> java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
> 	at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:715)
> 	at org.apache.commons.jexl2.parser.ASTEmptyFunction.jjtAccept(ASTEmptyFunction.java:18)
> 	at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:1364)
> 	at org.apache.commons.jexl2.parser.ASTReturnStatement.jjtAccept(ASTReturnStatement.java:18)
> 	at org.apache.commons.jexl2.Interpreter.visit(Interpreter.java:946)
> 	at org.apache.commons.jexl2.parser.ASTJexlScript.jjtAccept(ASTJexlScript.java:38)
> 	at org.apache.commons.jexl2.Interpreter.interpret(Interpreter.java:232)
> 	at org.apache.commons.jexl2.ExpressionImpl.execute(ExpressionImpl.java:107)
> 
> See the example below.
> 
> 
> BTW how an empty map could be created? The {} literal is not valid jexl syntax.
> 
> Best regards,
>   Tomas
> 
> ---------------------------------
> public class Test04 {
> 
> 	private final static String[] SCRIPTS = {
> 		"var x = null; return empty(x);",
> 		"var x = ''; return empty(x);",
> 		"var x = 'abc'; return empty(x);",
> 		"var x = 0; return empty(x);",
> 		"var x = 333; return empty(x);",
> 		"var x = []; return empty(x);",
> 		"var x = [1, 2]; return empty(x);",  // === ERROR ===
> 		"var x = ['a', 'b']; return empty(x);",
> 		// "var x = {}; return empty(x);",
> 		"var x = {1:'A', 2:'B'}; return empty(x);",
> 	};
> 
> 	public static void main(String[] args) {
> 		JexlEngine jexl = new JexlEngine();
> 		JexlContext jc = new MapContext();
> 		Script script;
> 
> 		for (String stext : SCRIPTS) {
> 			System.out.println(stext);
> 			script = jexl.createScript(stext);
> 			try {
> 				Object ret = script.execute(jc);
> 				System.out.println(ret);
> 			} catch (Exception e) {
> 				e.printStackTrace();
> 			}
> 		}
> 		
> 	}
> 
> }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>