diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java index e821430153a..31b02615649 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,9 @@ import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.ReflectivePropertyAccessor; /** - * An Indexer can index into some proceeding structure to access a particular piece of it. Supported structures are: - * strings/collections (lists/sets)/arrays - * + * An Indexer can index into some proceeding structure to access a particular piece of it. + * Supported structures are: strings/collections (lists/sets)/arrays + * * @author Andy Clement * @since 3.0 */ @@ -114,7 +114,7 @@ public class Indexer extends SpelNodeImpl { if ((targetObject instanceof Collection ) || targetObject.getClass().isArray() || targetObject instanceof String) { int idx = (Integer)state.convertValue(index, TypeDescriptor.valueOf(Integer.class)); if (targetObject.getClass().isArray()) { - return new TypedValue(accessArrayElement(targetObject, idx),TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType())); + return new TypedValue(accessArrayElement(targetObject, idx), targetObjectTypeDescriptor.getElementTypeDescriptor()); } else if (targetObject instanceof Collection) { Collection c = (Collection) targetObject; if (idx >= c.size()) { @@ -125,7 +125,7 @@ public class Indexer extends SpelNodeImpl { int pos = 0; for (Object o : c) { if (pos == idx) { - return new TypedValue(o,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType())); + return new TypedValue(o, targetObjectTypeDescriptor.getElementTypeDescriptor()); } pos++; } @@ -218,7 +218,7 @@ public class Indexer extends SpelNodeImpl { } if (targetObject instanceof List) { List list = (List)targetObject; - Object possiblyConvertedValue = state.convertValue(newValue,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType())); + Object possiblyConvertedValue = state.convertValue(newValue, targetObjectTypeDescriptor.getElementTypeDescriptor()); list.set(idx,possiblyConvertedValue); return; } @@ -278,7 +278,7 @@ public class Indexer extends SpelNodeImpl { Object newCollectionElement = null; try { int newElements = index-collection.size(); - if (elementType == null) { + if (elementType == null || elementType == Object.class) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE); } while (newElements>0) { diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java index a2a42392eb3..0698720ff1a 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,12 +34,12 @@ import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; /** - * Represents selection over a map or collection. For example: {1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this) == 'y'} returns - * [2, 4, 6, 8, 10] - * - * Basically a subset of the input data is returned based on the evaluation of the expression supplied as selection - * criteria. - * + * Represents selection over a map or collection. + * For example: {1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this) == 'y'} returns [2, 4, 6, 8, 10] + * + *

Basically a subset of the input data is returned based on the + * evaluation of the expression supplied as selection criteria. + * * @author Andy Clement * @author Mark Fisher * @since 3.0 @@ -112,13 +112,13 @@ public class Selection extends SpelNodeImpl { int idx = 0; for (Object element : data) { try { - state.pushActiveContextObject(new TypedValue(element,TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType()))); + state.pushActiveContextObject(new TypedValue(element, op.getTypeDescriptor().getElementTypeDescriptor())); state.enterScope("index", idx); Object o = selectionCriteria.getValueInternal(state).getValue(); if (o instanceof Boolean) { if (((Boolean) o).booleanValue() == true) { if (variant == FIRST) { - return new TypedValue(element,TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType())); + return new TypedValue(element, op.getTypeDescriptor().getElementTypeDescriptor()); } result.add(element); } @@ -136,7 +136,7 @@ public class Selection extends SpelNodeImpl { return TypedValue.NULL; } if (variant == LAST) { - return new TypedValue(result.get(result.size() - 1),TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType())); + return new TypedValue(result.get(result.size() - 1), op.getTypeDescriptor().getElementTypeDescriptor()); } if (operand instanceof Collection) { return new TypedValue(result,op.getTypeDescriptor());