SPR-7244: double indexing with a collection of different types of element

This commit is contained in:
Andy Clement 2010-05-28 20:31:16 +00:00
parent d0393ea109
commit 5801af9ef5
2 changed files with 26 additions and 1 deletions

View File

@ -89,7 +89,7 @@ public class Indexer extends SpelNodeImpl {
}
// Indexing into a Map
if (targetObjectTypeDescriptor.isMap()) {
if (targetObject instanceof Map) {
if (targetObject == null) {
// Current decision: attempt to index into null map == exception and does not just return null
throw new SpelEvaluationException(getStartPosition(),SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);

View File

@ -17,6 +17,7 @@
package org.springframework.expression.spel;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
@ -28,6 +29,7 @@ import org.springframework.expression.BeanResolver;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParserContext;
import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.TypedValue;
@ -673,4 +675,27 @@ public class SpringEL300Tests extends ExpressionTestCase {
Assert.assertEquals("default", expr.getValue());
}
@Test
@SuppressWarnings("unchecked")
public void testMapOfMap_SPR7244() throws Exception {
Map<String,Object> map = new LinkedHashMap();
map.put("uri", "http:");
Map nameMap = new LinkedHashMap();
nameMap.put("givenName", "Arthur");
map.put("value", nameMap);
StandardEvaluationContext ctx = new StandardEvaluationContext(map);
ExpressionParser parser = new SpelExpressionParser();
String el1 = "#root['value'].get('givenName')";
Expression exp = parser.parseExpression(el1);
Object evaluated = exp.getValue(ctx);
Assert.assertEquals("Arthur", evaluated);
String el2 = "#root['value']['givenName']";
exp = parser.parseExpression(el2);
evaluated = exp.getValue(ctx);
Assert.assertEquals("Arthur",evaluated);
}
}