# Thread: SpEL Collection Selection Problem/Bug

#### Hybrid View

1. Senior Member
Join Date
Jan 2007
Posts
107

## SpEL Collection Selection Problem/Bug

Hi,

Have a look at the following code sample (junit test) which tries to do what is talked about in the following documentation.

http://static.springsource.org/sprin....html#d0e11694

Code:
@Test
@SuppressWarnings("unchecked")
public void testSelectionFromMap() {
Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
map.put(1, 1);
map.put(2, 2);
map.put(3, 3);
/*
* NOTE: select all map entries with value less than 3
*/
Map<Integer, Integer> all = (Map<Integer, Integer>) parser.parseExpression("#root.?[value<3]").getValue(map);
assertTrue(all.size() == 2);
Iterator<Integer> iterator = all.keySet().iterator();
assertTrue(iterator.next() == 1);
assertTrue(iterator.next() == 2);
/*
* NOTE: select first entry with value less than 3
*/
Map<Integer, Integer> first = (Map<Integer, Integer>) parser.parseExpression("#root.^[value<3]").getValue(map);
assertTrue(first.keySet().iterator().next() == 1);
/*
* NOTE: select last entry with value less than 3
*/
Map<Integer, Integer> last = (Map<Integer, Integer>) parser.parseExpression("#root.\$[value<3]").getValue(map);
assertTrue(last.keySet().iterator().next() == 2);
}
It fails because the last assertion fails. The variable 'last' actually has the value '{3=null}' instead of '{2=2}'. This works fine if I ask for all entries with values greater than 4 or above but with 3 or below it doesn't work as expected. Particularly why does the 'last' variable have an entry with a value of null?

Is this my misuse/oversight or is this a bug?

Thanks.

2. Senior Member
Join Date
Jan 2007
Posts
107
Seems like there is a bug open for this already which would explain it.

http://jira.springframework.org/browse/SPR-6590