Skip to content

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

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

Closed
spring-projects-issues opened this issue Sep 23, 2020 · 0 comments · Fixed by #1195
Assignees
Labels
type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Sep 23, 2020

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

@spring-projects-issues spring-projects-issues added the type: enhancement A general enhancement label Dec 31, 2020
mikereiche added a commit that referenced this issue Aug 17, 2021
Also just use the first projected property instead of one explicitly named "count".

Closes #925,#960..
mikereiche added a commit that referenced this issue Aug 18, 2021
…1195)

Also just use the first projected property instead of one explicitly named "count".

Closes #925,#960.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
2 participants