"Iterator.next()" which can't throw NoSuchElementException

I have some code which triggers the above inspection, but I believe
should not:

private class SomeInnerClass implements Iterator {
// blah blah...

public Object next() {
return nextEntry();
}

protected final Entry nextEntry() {
// blah blah...

if (mCurrentEntry == null && !hasNext()) {
throw new NoSuchElementException();
}

// blah blah...
}
}

Is the inspection wrong? Neither next() nor nextEntry() are declared as
"throws NoSuchElementException" but neither is Iterator's, so I don't
think that's the problem.

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

2 comments

Hi Gordon,

The inspection is indeed wrong. Could you submit a JIRA request?

Bas

Gordon Tyler wrote:

I have some code which triggers the above inspection, but I believe
should not:

private class SomeInnerClass implements Iterator {
// blah blah...

public Object next() {
return nextEntry();
}

protected final Entry nextEntry() {
// blah blah...

if (mCurrentEntry == null && !hasNext()) {
throw new NoSuchElementException();
}

// blah blah...
}
}

Is the inspection wrong? Neither next() nor nextEntry() are declared as
"throws NoSuchElementException" but neither is Iterator's, so I don't
think that's the problem.

Ciao,
Gordon

0

http://www.jetbrains.net/jira/browse/IDEA-5456

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0

Please sign in to leave a comment.