[
https://issues.apache.org/jira/browse/GROOVY-7960?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John Wagenleitner updated GROOVY-7960:
--------------------------------------
Description:
Calling {{next()}} on an {{IntRange}} iterator returns {{null}} when
{{hasNext{}}} returns false. As stated in a comment in the class, it should
throw {{NoSuchElementException}} to adhere to the Iterator contract.
{code}
class IntRangeItrTest extends GroovyTestCase {
void testItr() {
def itr = (1..2).iterator()
assert itr.next() == 1
assert itr.next() == 2
assert !itr.hasNext()
shouldFail(NoSuchElementException) {
itr.next() // null
}
}
}
{code}
was:
Calling {{next()}} on an {{IntRange}} iterator returns {{null}} when
{{hasNext{}}} returns false. As stated in a comment in the class, it should
throw {{NoSuchElementException}} to adhere to the Iterator contract.
{code}
class IntRangeItrTest extends GroovyTestCase {
void testItr() {
def itr = (1..2).iterator()
assert itr.next() == 1
assert itr.next() == 2
assert !itr.hasNext()
shouldFail(NoSuchElementException) {
itr.next() // null
}
}
}
{code}
See PR# 412
https://github.com/apache/groovy/pull/412
> IntRange iterator returns null instead of NoSuchElementException
> ----------------------------------------------------------------
>
> Key: GROOVY-7960
> URL: https://issues.apache.org/jira/browse/GROOVY-7960
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.4.7
> Reporter: John Wagenleitner
> Assignee: John Wagenleitner
> Priority: Minor
>
> Calling {{next()}} on an {{IntRange}} iterator returns {{null}} when
> {{hasNext{}}} returns false. As stated in a comment in the class, it should
> throw {{NoSuchElementException}} to adhere to the Iterator contract.
> {code}
> class IntRangeItrTest extends GroovyTestCase {
> void testItr() {
> def itr = (1..2).iterator()
> assert itr.next() == 1
> assert itr.next() == 2
> assert !itr.hasNext()
> shouldFail(NoSuchElementException) {
> itr.next() // null
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)