The ^ operator is a bitwise operator, not a logical operator. With a technical fix, operator precedence makes an expression confused if logical expressions grow. I do not use FindBugs, but I would call the suspect the third line - wrap it in parentheses or rewrite it.
... } else if ((first == null) ^ (second == null)) { ...
^ can behave like a logical operation if the operands are logical values. Since the priority is different for each logical and bitwise operator, you should always group with parentheses, since the evaluation order will not be left to the right, but will be based on the table here: http://docs.oracle.com/javase/tutorial/java/ nutsandbolts / operators.html
Your expression "not as null" and "not not not null" is as follows:
(first == null) || second == null) && !((first == null && second == null))
This is pretty confusing, but this is what you are asking for.
I'm not sure what you are doing in blocks, but it might be easier to write the whole block as follows:
if(first!=null && !first.equals(second)) { // first is not null and the first and second are not equal } else if (second!=null && !second.equals(first)) { // second is not null and first and second are not equal } else { // all that is left is that first and second are both null OR neither one is null but they are equal }
Nathaniel johnson
source share