From: YeongJong Lee Date: Thu, 29 Oct 2020 05:47:21 +0000 (+0900) Subject: [NUI] add null checking for equality operator of ControlState (#2079) X-Git-Tag: accepted/tizen/unified/20210219.040944~319 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48762057fec9f4bacf9e7e33d0094ccc7c701461;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] add null checking for equality operator of ControlState (#2079) This is patch to prevent a null reference exception in the following code. ```cs bool b = null == ControlState.Pressed; ``` Co-authored-by: Jiyun Yang --- diff --git a/src/Tizen.NUI/src/public/BaseComponents/ControlState.cs b/src/Tizen.NUI/src/public/BaseComponents/ControlState.cs index 5d60fc1..c393fcc 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/ControlState.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ControlState.cs @@ -226,7 +226,23 @@ namespace Tizen.NUI.BaseComponents /// A on the right hand side. /// true if the ControlStates are equal; otherwise, false. [EditorBrowsable(EditorBrowsableState.Never)] - public static bool operator ==(ControlState lhs, ControlState rhs) => lhs.Equals(rhs); + public static bool operator ==(ControlState lhs, ControlState rhs) + { + // Check for null on left side. + if (lhs is null) + { + if (rhs is null) + { + // null == null = true. + return true; + } + + // Only the left side is null. + return false; + } + // Equals handles case of null on right side. + return lhs.Equals(rhs); + } /// /// Compares whether the two ControlStates are different or not. @@ -235,7 +251,7 @@ namespace Tizen.NUI.BaseComponents /// A on the right hand side. /// true if the ControlStates are not equal; otherwise, false. [EditorBrowsable(EditorBrowsableState.Never)] - public static bool operator !=(ControlState lhs, ControlState rhs) => !lhs.Equals(rhs); + public static bool operator !=(ControlState lhs, ControlState rhs) => !(lhs == rhs); /// /// The addition operator.