I am having an issue with returning null value if condition is false with this function:
private <Optional>ServiceElements getPrice(final ServiceRequest serviceRequest,
final Date date,
final Integer code) {
if (isNotAFilter(serviceRequest.getCustomerId(),
serviceRequest.getStaffId()) {
return custRepository.getCustData(date, code).stream().filter(e -> e.getPrice() != null).filter(e -> e.getPrice >=0)
.findFirst();
}
return null;
}
private double calculate(final ServiceRequest serviceRequest)
{
return getPrice(serviceRequest).get().getPrice();
}
A java.lang.NullPointerException: null
was thrown instead of returning null value when calling getPrice
method.