Defensively check javaUtilOptionalEmpty

Issue: SPR-11888