-
Notifications
You must be signed in to change notification settings - Fork 192
Closed
Labels
type: enhancementA general enhancementA general enhancement
Description
Michael Reiche opened DATACOUCH-617 and commented
If a 'count' query does not return anything, a mysterious NPE is thrown.
@Query("SELECT 1 FROM `#{#n1ql.bucket}` WHERE nothing = `matches`)
Long count();
java.lang.NullPointerExceptionjava.lang.NullPointerException at org.springframework.data.couchbase.core.ExecutableFindByQueryOperationSupport$ExecutableFindByQuerySupport.count(ExecutableFindByQueryOperationSupport.java:90) at org.springframework.data.couchbase.repository.query.N1qlRepositoryQueryExecutor.execute(N1qlRepositoryQueryExecutor.java:70) at org.springframework.data.couchbase.repository.query.CouchbaseRepositoryQuery.execute(CouchbaseRepositoryQuery.java:42)
Adding a check for null would prevent the NPE, but silently ignoring that the query was erroneous is not a good solution.
@Override
public long count() {
Long l = reactiveSupport.count().block();
return l != null ? l.longValue() : 0;
}
Another possibility is changing the return type of the count() method to Long, so that it could actually be null.
Another possibility is explicitly throwing an exception if the return values is null.
No further details from DATACOUCH-617
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancementA general enhancement