Here is the sample code which I am trying to execute: Consider a list of Employees with List of Address.
employees.getAddresses.stream()
.filter(address -> address.getPincode!=null).findFirst()
.orElseThrow(() {
logger.error("Error message");//logging error message
CustomException() exception = new CustomException();//constructing custom exception
return exception;
});
But in the above code, if employees/addresses is null, it will throw NPE.I want to add a null check to employees and adresses field too and throw the same error which I am throwing in orElseThow block. is there a clean way of doing it. Is it possible to use the same "orElseThrow" for this null check.