Skip to content

bad "count" string queries throw mysterious NullPointerException [DATACOUCH-617] #925

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions