Details
Description
view iteration is incomplete and throws exceptions for
groovy code:
paginator = client.paginatedQuery(view, query, n)
while (paginator.hasNext()) {
row = paginator.next() // Exception on this line
...
}
java.util.NoSuchElementException
at java.util.LinkedList$ListItr.next(LinkedList.java:698)
at com.couchbase.client.protocol.views.Paginator.next(Paginator.java:76)
at com.couchbase.client.protocol.views.Paginator.next(Paginator.java:35)
at java_util_Iterator$next.call(Unknown Source)
AND
java.lang.NullPointerException
at com.couchbase.client.protocol.views.Paginator.getNextPage(Paginator.java:93)
at com.couchbase.client.protocol.views.Paginator.hasNext(Paginator.java:67)
at java_util_Iterator$hasNext.call(Unknown Source)
Paginator also has a couple odd returns
1) next() can return null, but it should never return null unless lastRow is null. I don't think lastRow should ever be null.
2) getNextPage() has a return type, HttpFuture<ViewResponse>, but always returns null
groovy code:
paginator = client.paginatedQuery(view, query, n)
while (paginator.hasNext()) {
row = paginator.next() // Exception on this line
...
}
java.util.NoSuchElementException
at java.util.LinkedList$ListItr.next(LinkedList.java:698)
at com.couchbase.client.protocol.views.Paginator.next(Paginator.java:76)
at com.couchbase.client.protocol.views.Paginator.next(Paginator.java:35)
at java_util_Iterator$next.call(Unknown Source)
AND
java.lang.NullPointerException
at com.couchbase.client.protocol.views.Paginator.getNextPage(Paginator.java:93)
at com.couchbase.client.protocol.views.Paginator.hasNext(Paginator.java:67)
at java_util_Iterator$hasNext.call(Unknown Source)
Paginator also has a couple odd returns
1) next() can return null, but it should never return null unless lastRow is null. I don't think lastRow should ever be null.
2) getNextPage() has a return type, HttpFuture<ViewResponse>, but always returns null
1) Check for a null ViewResponse in getNextPage and return the ViewResponse instead of a future or null. The hasNext method can then check the value of getNextPage returning false if there is no ViewResponse.
2) to bypass isJsonObject for numeric keys in Query.getArgs:
boolean numericKey = (key.equals(STARTKEY) && value.toString().matches("\\d+")); // still not json number but catches most common case of positive
integer keys if (key.equals(STARTKEYDOCID) || numericKey ) { return key + "=" + value;
3) Skip parameter needs to be zero for pages after the first. In Paginator:
public boolean hasNext() {
if (!pageItr.hasNext() && page.size() < docsPerPage) {
return false;
} else if (!(rowsIterated < docsPerPage)) {
lastRow = pageItr.next();
query.setSkip(0);
query.setStartkeyDocID(lastRow.getId());
query.setRangeStart(lastRow.getKey());
return (getNextPage(query) != null);
}
return true;
}