I m trying to use Optional.ofNullable on an a getter that is throwing a NullPointerException :
My code is as follow :
Individual individual = null;
Optional.ofNullable(individual.getIndividualName());
Throwing a NullPointerException here is normal since individual is null
I want to find a pretty way to avoid this exception and get null as result of
Optional.ofNullable(individual.getIndividualName());
The solution in Null check chain vs catching NullPointerException is very heavy. I try it in a jUnit test and takes several seconds to get the result!