Your question is based on suspicion that the code which may throw NullPointerException is worse than the code which may not. This hypothesis is wrong. If you expect that your foobar is never null due to the program logic, it's much better to use Optional.of(foobar) as you will see a NullPointerException which will symbolize that your program has a bug. If you use Optional.ofNullable(foobar) and the foobar appears to be null due to the bug, then your program will silently continue working incorrectly, which may be a greater disaster. This way an error may occur much later and it would be much harder to know at which point it went wrong.