Babak Vahdat created CAMEL-7096:
-----------------------------------

             Summary: The ObjectHelper#createIterator utility should properly 
adhere the java.util.Iterator contract
                 Key: CAMEL-7096
                 URL: https://issues.apache.org/jira/browse/CAMEL-7096
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 2.12.2
            Reporter: Babak Vahdat
            Assignee: Babak Vahdat
            Priority: Minor
             Fix For: 2.11.3, 2.12.3, 2.13.0


According to the {{java.util.Iterator#next()}} contract the implementation 
should throw {{NoSuchElementException}} if the iteration has no more elements. 
However this is currently not the case by the different anonymous class 
implemetations of this interface through {{ObjectHelper#createIterator()}}.

The side effect of this is that currently this could end up with 
{{IndexOutOfBoundsException}} and what not if one would iterate over the 
{{Node}}(s) of a DOM {{NodeList}}. Another example is that calling {{next()}} 
on the {{Iterator}} returned for an empty String *repeatedly* doesn't throw  
any {{NoSuchElementException}} *although* it's {{hasNext()}} method returns 
false!

We should better provide guards for the condition when there's no more elements 
available in which case a {{NoSuchElementException}} should be thrown.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to