Think found a bug where the Sonar Analysis wrongly reports possible null pointer exception when the first if boolean param has been set by Bitwise exclusive Or “^”.
Rule
A “NullPointerException” could be thrown; “oldProspectFieldSetting” is nullable here.
Get permalink
Null pointers should not be dereferenced. java:S2259
Workaround
// SonarQube workaround, using 'Logical or' Operator instead of 'Bitwise exclusive OR' to avoid wrongly reported potential null pointer error
final boolean toOrFromNull = Objects.isNull(newProspectFieldSetting) || Objects.isNull(oldProspectFieldSetting);
if (toOrFromNull || !objectOne.getName().equals(objectTwo.getName())) {
// bla bla
}
SonarQube Bug (Reporting)
final boolean toOrFromNull = Objects.isNull(objectOne) ^ Objects.isNull(objectTwo);
if (toOrFromNull || !objectOne.getName().equals(objectTwo.getName())) {
// bla bla
}