Tony Hoare is said to have invented, what we now call
null. And he regretted it:
I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years
Now we have to live and deal with it.
however I don't know how to handle unknown dates.
Trust me, you are not alone.
The problem is, that there is something I would call ambiguity of information. Asking »when was the battle of waterloo?« in everyday life »I don't know« is an accepted answer. But it is not the answer about the date itself, it is about the knowledge of the speaker.
To your problem: Asking
person.getBirthDate() gives you an ambigous answer:
What is a proper solution to that misery of ambiguity?
Since, we have
null and since it is widely accepted across datastores, you should use
null as a correct answer in the context of the DB.
But what about your programm:
As you correctly said
because it's resulting in null pointer exceptions when I try to compare dateOfBirth to other dates such as the LocalDate.now()
You have to guard against that in some way or the other:
1) You could introduce a getter
person.birthdayKnown() to do the following:
if (personA.birthdayKnown() && personA.birthdayKnown()) // allow further operations
2) With the advent of Java8, you could make it an Optional and work with