title: Spring boot rest API - Querydsl, predicate must not be null
body: <p>Is the <code>Predicate</code> supposed to be nullable using <code>MongoRepository</code>?</p>
  
  <p>The standard JPA <code>PagingAndSortingRepository</code> always seems to return a valid <code>Predicate</code>, no matter which query parameters are provided.</p>
  
  <p><strong>Stacktrace</strong></p>
  
  <pre><code>java.lang.IllegalArgumentException: Predicate must not be null!
          at org.springframework.util.Assert.notNull(Assert.java:198) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
          at org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor.findAll(QuerydslMongoPredicateExecutor.java:165) ~[spring-data-mongodb-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
          at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
          at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
          at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
          at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
          at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
          at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
  </code></pre>
  
  <p><strong>Curl</strong></p>
  
  <pre><code>http://localhost:8080/api/notifications?page=1 # stacktrace
  http://localhost:8080/api/notifications?id=1&amp;page=1" # does work
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@RestController
  @RequestMapping(produces = "application/json; charset=UTF-8")
  @Api(description = "Operations concerning notifications")
  public class NotificationController {
  
      @Autowired
      private NotificationFacade notificationFacade;
  
      @Autowired
      private NotificationRepository notificationRepository;
  
      @ApiOperation(value = "Retrieve a list of available notifications")
      @GetMapping("/api/notifications")
      public Page&lt;Notification&gt; findAll(@QuerydslPredicate() Predicate predicate,
                                        @PageableDefault(sort = "id") Pageable pageable) {
          return notificationRepository.findAll(predicate, pageable);
      }
  
  }
  </code></pre>
  
  <p><strong>Repository</strong></p>
  
  <pre><code>public interface NotificationRepository extends MongoRepository&lt;Notification, String&gt;, QuerydslPredicateExecutor&lt;Notification&gt; {}
  </code></pre>
  
  <p><strong>Entity</strong></p>
  
  <pre><code>@Data
  @Document(collection = "notifications")
  public class Notification {
  
      @Id
      private String id;
  
      @NonNull
      private String message;
  
  
  
  }
  </code></pre>