Method parse(CharSequence, DateTimeFormatter) of the java.time.LocalDateTime class does not accept null as the character sequence (first parameter), so you have to make an explicit null-check and rewrite the return from your function as return if (dateEmailSent != null) LocalDateTime.parse(dateEmailSent, formatter) else null