Checking the validity of input Cursors#260
Closed
emopers wants to merge 2 commits into
Closed
Conversation
ctrueden
reviewed
Aug 15, 2019
ctrueden
left a comment
Member
There was a problem hiding this comment.
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:
- Consistency of which kind of exception to throw if things go awry; and
- The "fix spacing" commit would ideally be squashed into the first commit, which would follow best practices for its commit message.
| { | ||
| if ( !dst.hasNext() ) | ||
| { | ||
| throw new NoSuchElementException("Cursor does not have next element"); |
Member
There was a problem hiding this comment.
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"); |
Member
There was a problem hiding this comment.
Similarly: should we use fail here?
Member
|
Upon further reflection, I am ambivalent about this. See #259 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.