title: Java collapsible if statements
body: <p>I use <a href="http://pmd.sourceforge.net" rel="nofollow">PMD</a> to check my code. It gives me very useful hints in most cases, but I can't figure out what could be improved in the following scenario.</p>
  
  <p>The original code looks something like this:</p>
  
  <pre><code>if ((getSomething() != null &amp;&amp; getSomethingElse() != null)
       || (getSomething() == null &amp;&amp; getSomethingElse() == null))
  {
     ...
  }
  </code></pre>
  
  <p>PMD tells me:</p>
  
  <blockquote>
    <p>Sometimes two 'if' statements can be consolidated by separating their
    conditions with a boolean short-circuit operator.</p>
  </blockquote>
  
  <p>For simplicity, let's just use a and b as boolean variables. Then this piece of code looks like this:</p>
  
  <pre><code>if ((!a &amp;&amp; !b) || (a &amp;&amp; b))
  </code></pre>
  
  <p>This can be transformed to one of the following:</p>
  
  <pre><code>if ((!a || b) &amp;&amp; (a || !b))
  if (!(a^b))
  </code></pre>
  
  <p>and finally</p>
  
  <pre><code>if (a==b)
  </code></pre>
  
  <p>So I simplified my code to</p>
  
  <pre><code>if ((getSomething() == null) == (getSomethingElse() == null))
  </code></pre>
  
  <p>However, PMD keeps complaining (in fact about all three versions). Is this a false positive or is there a better way of writing the if-condition?</p>