Announcement Announcement Module
No announcement yet.
SpEL Collection Selection Problem/Bug Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SpEL Collection Selection Problem/Bug


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

        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( == 1);
            assertTrue( == 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?


  • #2
    Seems like there is a bug open for this already which would explain it.