You need to sign in to do that
Don't have an account?

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(opp.id, trigger.oldMap.get(opp.id));
}
Regards
In the highlighted line above it should be an 'And' condition i.e (opp.ExpectedRevenue != null && opp.ExpectedRevenue != 0.0)
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?