Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking the validity of input Cursors #260

Closed
wants to merge 2 commits into from

Conversation

emopers
Copy link

@emopers emopers commented Jul 19, 2019

These tests calls of Cursor.next() without checking if there are any elements to iterate over. Because the method is public and the iterators are obtained from inputs, they could be invalid (e.g., an empty list). This could lead to an exception. This pull request adds a 'hasNext()' check.

Copy link
Member

@ctrueden ctrueden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @emopers. These changes certainly seem like a good idea to me. @tpietzsch What do you think? It's only additional sanity checks in the tests, so no performance impact on the library. My only (nitpicking) concerns are:

  1. Consistency of which kind of exception to throw if things go awry; and
  2. The "fix spacing" commit would ideally be squashed into the first commit, which would follow best practices for its commit message.

@@ -130,6 +131,10 @@ public void copyWithIterationBoth( final Img< IntType > srcImg, final Img< IntTy
final Cursor< IntType > dst = dstImg.cursor();
while ( src.hasNext() )
{
if ( !dst.hasNext() )
{
throw new NoSuchElementException("Cursor does not have next element");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better to call JUnit's fail method here, for consistency? These methods, while public, are only intended for use from unit tests, right?

{
if ( !dst.hasNext() )
{
throw new NoSuchElementException("Cursor dst does not have next element");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly: should we use fail here?

@ctrueden
Copy link
Member

Upon further reflection, I am ambivalent about this. See #259 (comment)

@ctrueden ctrueden closed this Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants