I receive a Customer object which contains lastName and firstName. In the conversion I check if both values are not empty and then pass them into the DTO:
if (customer.getFirstName().isPresent() && customer.getLastName().isPresent()) {
final String firstName = customer.getFirstName().get();
final String lastName = customer.getLastName().get();
// do assignment
}
But I still get the Sonar message Optional value should only be accessed after calling isPresent().
Am I missing something here or is this a false positive?