Fix defect that is detected by static analisys tool (#5805)
authorurmain <wn.jang@samsung.com>
Wed, 6 Dec 2023 08:45:10 +0000 (17:45 +0900)
committerGitHub <noreply@github.com>
Wed, 6 Dec 2023 08:45:10 +0000 (17:45 +0900)
There is a portential problem with the code involving the variable 'e.OldItems'.
This variable is the result of a method invocation, and the tool is warning that the method
might return a null value, which can cause deferencing a null reference.
It might cause to crash or behave unpredictably.

Therefore, to prevent this, the variable 'e.OldItems' should be checked if it is null or not before use.

src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommandsGroup.cs

index bc37931..c76eb39 100644 (file)
@@ -128,13 +128,19 @@ namespace Tizen.Uix.VoiceControlManager
         {
             if (e.Action == NotifyCollectionChangedAction.Add)
             {
-                foreach (VoiceCommand item in e.NewItems)
-                    Add(item);
+                if (e.NewItems!= null && e.NewItems.Count > 0)
+                {
+                    foreach (VoiceCommand item in e.NewItems)
+                        Add(item);
+                }
             }
             else if (e.Action == NotifyCollectionChangedAction.Remove)
             {
-                foreach (VoiceCommand item in e.OldItems)
-                    Remove(item);
+                if (e.OldItems!= null && e.OldItems.Count > 0)
+                {
+                    foreach (VoiceCommand item in e.OldItems)
+                        Remove(item);
+                }
             }
         }