I use Java 8 and have an issue with how to check objects through Optional. It should be like
Optional.ofNullable(person)
        .map(Person::getAge)
        .filter(age -> age > 25)
        .orElseThrow(new CustomException())
However, this code returns the value, but I don't need this. How fix it? Code should be like this
If (noNPE && person.getAge() > 25) {
       // do nothing
} else {
       throw new CustomException();
}
I don't need return value due to sonar throw warnings.
 
     
     
    