function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ethan huntethan hunt 

broken null check

Hi All,

Could you please help me in resloving the below warning broken null check error --

if(trigger.isDelete) {
            for(Opportunity opp: trigger.old) {
          /////////broken null check      if((opp.ExpectedRevenue != null || opp.ExpectedRevenue != 0.0) && (opp.RecordTypeId == Label.Opportunity_Low_RecordType_ID
                    || opp.RecordTypeId == Label.Opportunity_Lower_Record_Type_Id) &&
                      opp.Opportunity_Hierarchy_Link__c != null) {
                    mapOldSubOpportunity.put(, trigger.oldMap.get(;



     In the highlighted line above it should be an 'And' condition i.e (opp.ExpectedRevenue != null && opp.ExpectedRevenue != 0.0)
I'm assuming this warning is coming from PMD.

The reason for this is that you have checked if the field is not null OR 0.0 - this is considered a broken null check as the right hand side of the OR will be evaluated if the field is equal to null.  If you check for expectedrevenue equal to null, the right hand side will not be evaluated unless it is a different value, as false OR anything is always false.

I don't actually think that will throw a null pointer exception in Apex, but it would in Java.

Can you explain what the purpose of the test is?