I'm seeing some trange behaviour using the elvis operator in SpEL. If I don't surround the elvis expression in brackets "()" then the result of the elvis operator is returned and the rest of the expression is ignored. Sample Code showing the behaviour below:
HashMap<String, String> facts = new HashMap<String, String>();
facts.put("flag", "flagvalue");
String expressionString;
Expression expression;
Object expressionResult;
expressionString = "[flag]?:'' matches '(?i)flagvalue'";
expression = new SpelExpressionParser().parseExpression(expressionString);
expressionResult = expression.getValue(facts);
System.out.println("Unexpected Result:" + expressionResult);
expressionString = "([flag]?:'') matches '(?i)flagvalue'";
expression = new SpelExpressionParser().parseExpression(expressionString);
expressionResult = expression.getValue(facts);
System.out.println("Expected Result:" + expressionResult);
Output:
Unexpected Result:flagvalue
Expected Result:true
The strange part is when the value is not in the hashmap (i.e comment the facts.put line) the elvis operator appears to work fine and both expressions return false as expected.
(using spring-framework-3.0.5)