title: Converting java.sql.Date & java.util.Date to org.joda.time.LocalDate
body: <p>I am trying to carefully and meticulously clean up some of my older (production) code. One thing I am trying to do is convert all my usages of <code>java.util.Date</code> to <code>LocalDate</code> and <code>DateTime</code>.</p>
  
  <p>However, I noticed one big obstacle tonight as I was working. I had this code:</p>
  
  <pre><code>ResultSet results = stmt.executeQuery();
  
  Date last = results.getDate("LAST_DELIVERY_DATE");
  Date next = results.getDate("NEXT_DELIVERY_DATE");
  boolean received;
  if (last == null &amp;&amp; next == null) {
      received = true; // order is not open
  } else if (last == null) {
      received = false;
  } else {
      received = true;
  }
  </code></pre>
  
  <p>I converted <code>last</code> and <code>next</code> to:</p>
  
  <pre><code>LocalDate last = new LocalDate(results.getDate("LAST_DELIVERY_DATE"));
  LocalDate next = new LocalDate(results.getDate("NEXT_DELIVERY_DATE"));
  </code></pre>
  
  <p>and Netbeans underlined the <code>if == null</code> and said:</p>
  
  <pre><code>Unnecessary test for null - the expression is never null
  </code></pre>
  
  <p>This makes sense, because a new <code>LocalDate</code> instance won't be null (no <code>new Object()</code> can be).</p>
  
  <p><strong>BUT</strong>, in this case and in many cases throughout my program, a <code>null</code> date communicates some essential information. In this case, it shows whether the order 1) is open (or not), 2) has been received (or not).</p>
  
  <p>So, trying to find ways around it, I figured I could instead use this code:</p>
  
  <pre><code>LocalDate last = results.getDate("LAST_DELIVERY_DATE") == null? null : new LocalDate(results.getDate("LAST_DELIVERY_DATE"));
  LocalDate next = results.getDate("NEXT_DELIVERY_DATE") == null? null : new LocalDate(results.getDate("NEXT_DELIVERY_DATE"));
  </code></pre>
  
  <p>But, this just seems ugly to me? Plus, it calls the "ResultSet#getDate()" function twice, which.... correct me if I'm wrong... makes two calls to the database, right?. So, now to convert my code to joda-time I am essentially doubling the time it takes to get <code>java.sql.Date</code> objects from the database...</p>
  
  <pre><code>LocalDate last = LocalDate.fromDateFields(results.getDate("LAST_DELIVERY_DATE"));
  LocalDate next = LocalDate.fromDateFields(results.getDate("NEXT_DELIVERY_DATE"));
  </code></pre>
  
  <p>doesn't work, either, because <code>fromDateFields</code> throws a <code>NullPointerException</code> when it gets a <code>null</code> value.</p>
  
  <p>So, my question is: how do you best handle null dates when your program necessitates <strong>having</strong> null dates and joda-time? Am I missing something? Is there an easier way to accomplish what I'm after?</p>