JPA Specification with null parameter

I have created JPA Specification like

public class CarFilterSpecs {
  public static Specification<Car> carStatusIn(Collection<String> carStatus) {
    return (root, query, builder) ->
                    ? builder.conjunction()
                    : carStatus.contains(-1)
                    ? builder.isNull(root.get("carStatus").get("id"))
                    : root.get("carStatus").get("id").in(carStatus);

  public static Specification<Car> carVisibilityStatusIn(Collection<String> 
    carVisibilityStatus) {
    return (root, query, builder) ->
            ? builder.conjunction()
            : carVisibilityStatus.contains(-1)
            ? builder.isNull(root.get("carVisibilityStatus"))
            : root.get("carVisibilityStatus").in(carVisibilityStatus);

and models looks like

public class Status {
  String id;
  String name;

public class Car {
  String id;
  Status status;

and I am consuming the spec like


Specification<Car> specs = Specification.where(CarSpecs.carStatusIn(status))


till here works perfectly but now I am failing to get cars with some status and as well cars with status null(there is a chance of having status null)

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum