Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
2.7
-
None
-
None
-
Important
Description
If the IN clause is used with Strings, only the last element in the String is tested.
public static void main(String[] args) throws OgnlException
{ String exp = "( #name == \"Andromeda\" || #name in (\"Greenland\", \"Austin\", \"Africa\", \"Rome\") || #number in (100, 300, 450) )"; Object expression = Ognl.parseExpression(exp); Object root = null; Map<Object, Object> context = new HashMap<Object, Object>(); System.out.println(exp); context.put("name", "Austin"); context.put("number", "7777"); Object retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Africa"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Greenland"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Rome"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Andromeda"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Iceland"); context.put("number", "300"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); // ----------- exp = "( #name == \"Andromeda\" || #name in (\"Rome\", \"Africa\", \"Greenland\", \"Austin\") || #number in (100, 300, 450) )"; expression = Ognl.parseExpression(exp); System.out.println(); System.out.println(exp); context.put("name", "Austin"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Africa"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Greenland"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Rome"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Andromeda"); context.put("number", "7777"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); context.put("name", "Iceland"); context.put("number", "300"); retVal = Ognl.getValue(expression, context, root); System.out.println(retVal + " for: " + context); }============================
Results:
( #name == "Andromeda" || #name in ("Greenland", "Austin", "Africa", "Rome") || #number in (100, 300, 450) )
false for:
{name=Austin, number=7777}false for: {name=Africa, number=7777}
false for: {name=Greenland, number=7777}
true for: {name=Rome, number=7777}
true for: {name=Andromeda, number=7777}
true for: {name=Iceland, number=300}
( #name == "Andromeda" || #name in ("Rome", "Africa", "Greenland", "Austin") || #number in (100, 300, 450) )
true for: {name=Austin, number=7777}
false for:
{name=Africa, number=7777}false for:
{name=Greenland, number=7777}false for:
{name=Rome, number=7777}true for:
{name=Andromeda, number=7777}true for:
{name=Iceland, number=300}