ipavlic/apex-fp

FieldsMatch/PrimitiveComparer: Why are null values from field not contemplated?

joaquiniudica opened this issue · 1 comments

I have a question, because I'm having trouble with one of my tests because of this.

In the "compare" method of the PrimitiveComparer class, you check if both values are of the same type to do the comparison. But there is one problem for me: What if fieldValue is null? null is not an instance of any type, so when fieldValue is null, and condition.value is not null, the compare method is called anyway and a lambdaException is thrown.

For instance, in the comparisonConditionSatisfied method in FieldsMatch class, if condition.value is null, then you compare fieldValue to null. But why don't you add, if comparison.value != null and fieldValue is null, return false?

I'm not an experienced programmer, and I don't know the repercussions to the rest of the system, so I would appreciate a quick explanation on this.

Am I supposed to skip records with null field values before filtering?

I appreciate the response, and I'm sorry if it is an obvious one.

Your proposal sounds reasonable. I haven't had much free time lately to do it myself, but feel free to submit a pull request.