title: Check if a String is null or empty when it's null sometimes and sometimes not
body: <p>Well I dont usually write this kind of questions, but even after checking:</p>
  
  <p><a href="https://stackoverflow.com/questions/3598770/java-check-whether-a-string-is-not-null-and-not-empty">Java, check whether a string is not null and not empty?</a> and <a href="https://stackoverflow.com/questions/14721397/checking-if-a-string-is-empty-or-null-in-java">Checking if a string is empty or null in Java</a>.</p>
  
  <p>My program creates a PDF with the information that has changed in the original contract and the modified one, but only these information. If the information is the same in both contracts it's not painted. But if it's not, then it paints it. </p>
  
  <p>I have no problem when there's something in both contracts, for example notes.</p>
  
  <p>If on the original contract they don't write anything but they do on the modification (Endorsement), then the system should not paint anything of the notes field. Same if they wrote something and delete it on modification. Here's where the problem lies.</p>
  
  <p>When I try to compare:</p>
  
  <pre><code>if ((sSPA.getNotes() == null ||
       sSPA.getNotes().length() == 0) &amp;&amp;
      (sSPE.getNotes() != null ||
       sSPE.getNotes().length() != 0)) {
      //Some stuff here
  }
  </code></pre>
  
  <p>I've tried too</p>
  
  <pre><code>if ((sSPA.getNotes() == null ||
       sSPA.getNotes().equals("")) &amp;&amp;
      (sSPE.getNotes() != null ||
       !sSPE.getNotes().equals(""))) {
      //Some stuff here
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>if ((sSPA.getNotes() == null ||
       sSPA.getNotes().isEmpty()) &amp;&amp;
      (sSPE.getNotes() != null ||
       !sSPE.getNotes().isEmpty())) {
      //Some stuff here
  }
  </code></pre>
  
  <p>I get the following error in log in execute time:</p>
  
  <pre><code>java.lang.NullPointerException
  at com.dnhr.rwa.server.document.PdfEndorsement.renderSubscriptionSubmissionProp(PdfEndorsement.java:1545)
  </code></pre>
  
  <p>And I know it's because the field is <code>null</code> and I'm trying to get it's length, or compare it to an empty string, and it's trying to do:</p>
  
  <p><code>if (null.equals("")) {</code> and that throws the exception same with <code>length()</code> method.</p>
  
  <p>And if I try doing:</p>
  
  <pre><code>if ((sSPA.getNotes() == null ||
       getStringValue(sSPA.getNotes().equals(""))) &amp;&amp;
      (sSPE.getNotes() != null ||
       !getStringValue(sSPE.getNotes().equals("")))) {
      //Some stuff here
  }
  </code></pre>
  
  <p>It returns the following error in compile time:</p>
  
  <pre><code>[javac] /home/efrain/proyectos/rwa-test/trunk/src/com/dnhr/rwa/server/document/PdfEndorsement.java:1541: error: bad operand types for binary operator '||'
  [javac]     if ((sSPA.getNotes() == null ||
  [javac]                                       ^
  [javac]   first type:  boolean
  [javac]   second type: String
  </code></pre>
  
  <p>Is there any other way to compare if the field is null or empty</p>
  
  <p>Here's an example of how I compare the 3 possibilities:</p>
  
  <pre><code>if((sSPA.getNotes() == null || sSPA.getNotes().trim().equals("")) &amp;&amp;
      (sSPE.getNotes() != null || !sSPE.getNotes().equals(""))) {
      //some stuff
  } else if(!getStringValue(sSPA.getNotes()).
        equals(getStringValue(sSPE.getNotes())) &amp;&amp;
        (sSPE.getNotes() == null || 
         sSPE.getNotes().trim().equals(""))) {
          //some stuff
  } else if(!getStringValue(sSPA.getNotes()).
        equals(getStringValue(sSPE.getNotes()))) {
          //some stuff
  }
  </code></pre>