[NUI] Fix Svace issue (#534)
authorhuiyueun <35286162+huiyueun@users.noreply.github.com>
Tue, 6 Nov 2018 08:30:22 +0000 (17:30 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 6 Nov 2018 08:30:22 +0000 (17:30 +0900)
Add to check Null value

Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs
src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs
src/Tizen.NUI/src/internal/Xaml/MarkupExpressionParser.cs
src/Tizen.NUI/src/internal/XamlBinding/BindablePropertyConverter.cs
src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs
src/Tizen.NUI/src/internal/XamlBinding/SynchronizedList.cs
src/Tizen.NUI/src/internal/XamlBinding/TizenPlatformServices.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs

index cb28b7a..a174eff 100755 (executable)
@@ -100,6 +100,8 @@ namespace Tizen.NUI.Xaml
             if (propertyName != XmlName.Empty || TryGetPropertyName(node, parentNode, out propertyName)) {
                 if (Skips.Contains(propertyName))
                     return;
+                if (parentElement == null)
+                    return;
                 if (parentElement.SkipProperties.Contains(propertyName))
                     return;
 
@@ -234,7 +236,7 @@ namespace Tizen.NUI.Xaml
             if (value.GetType().GetTypeInfo().GetCustomAttribute<AcceptEmptyServiceProviderAttribute>() == null)
                 serviceProvider = new XamlServiceProvider(node, Context);
 
-            if (serviceProvider != null && propertyName != XmlName.Empty)
+            if (serviceProvider != null && serviceProvider.IProvideValueTarget != null && propertyName != XmlName.Empty)
                 ((XamlValueTargetProvider)serviceProvider.IProvideValueTarget).TargetProperty = GetTargetProperty(source, propertyName, Context, node);
 
             if (markupExtension != null)
@@ -607,7 +609,7 @@ namespace Tizen.NUI.Xaml
             if (addMethod == null)
                 return false;
 
-            if (serviceProvider != null)
+            if (serviceProvider != null && serviceProvider.IProvideValueTarget != null)
                 ((XamlValueTargetProvider)serviceProvider.IProvideValueTarget).TargetProperty = targetProperty;
 
             addMethod.Invoke(collection, new [] { value.ConvertTo(addMethod.GetParameters() [0].ParameterType, (Func<TypeConverter>)null, serviceProvider) });
index 1e759f3..c148a6b 100755 (executable)
@@ -290,9 +290,16 @@ namespace Tizen.NUI.Xaml
                 INode node;
                 if (!enode.Properties.TryGetValue(name, out node))
                 {
-                    throw new XamlParseException(
-                        String.Format("The Property {0} is required to create a {1} object.", propname, ctorInfo.DeclaringType.FullName),
-                        enode as IXmlLineInfo);
+                    String msg = "";
+                    if (propname != null)
+                    {
+                        msg = String.Format("The Property {0} is required to create a {1} object.", propname, ctorInfo.DeclaringType.FullName);
+                    }
+                    else
+                    {
+                        msg = "propname is null.";
+                    }
+                    throw new XamlParseException(msg, enode as IXmlLineInfo);
                 }
                 if (!enode.SkipProperties.Contains(name))
                     enode.SkipProperties.Add(name);
index 6dbc21a..188ec53 100755 (executable)
@@ -57,7 +57,7 @@ namespace Tizen.NUI.Xaml
                 throw new Exception("Expression did not end in '}'");
 
             var parser = Activator.CreateInstance(GetType()) as IExpressionParser;
-            return parser.Parse(match, ref expression, serviceProvider);
+            return parser?.Parse(match, ref expression, serviceProvider);
         }
 
         internal static bool MatchMarkup(out string match, string expression, out int end)
index 5dfd12d..9f99006 100755 (executable)
@@ -104,7 +104,7 @@ namespace Tizen.NUI.Binding
                 throw new XamlParseException($"Can't resolve {name} on {type.Name}", lineinfo);
             var bp = bpinfo.GetValue(null) as BindableProperty;
             var isObsolete = bpinfo.GetCustomAttribute<ObsoleteAttribute>() != null;
-            if (bp.PropertyName != propertyName && !isObsolete)
+            if (bp != null && bp.PropertyName != propertyName && !isObsolete)
                 throw new XamlParseException($"The PropertyName of {type.Name}.{name} is not {propertyName}", lineinfo);
             return bp;
         }
index c4dd7f6..215cb82 100755 (executable)
@@ -342,40 +342,46 @@ namespace Tizen.NUI.Binding
 
             if (property != null)
             {
-                if (property.CanRead && property.GetMethod.IsPublic && !property.GetMethod.IsStatic)
-                    part.LastGetter = property.GetMethod;
-                if (property.CanWrite && property.SetMethod.IsPublic && !property.SetMethod.IsStatic)
+                if (property.CanRead && property.GetMethod != null)
                 {
-                    part.LastSetter = property.SetMethod;
-                    part.SetterType = part.LastSetter.GetParameters().Last().ParameterType;
-
-                    if (Binding.AllowChaining)
+                    if (property.GetMethod.IsPublic && !property.GetMethod.IsStatic)
+                        part.LastGetter = property.GetMethod;
+                }
+                if (property.CanWrite && property.SetMethod != null)
+                {
+                    if(property.SetMethod.IsPublic && !property.SetMethod.IsStatic)
                     {
-                        FieldInfo bindablePropertyField = sourceType.GetDeclaredField(part.Content + "Property");
-                        if (bindablePropertyField != null && bindablePropertyField.FieldType == typeof(BindableProperty) && sourceType.ImplementedInterfaces.Contains(typeof(IElementController)))
+                        part.LastSetter = property.SetMethod;
+                        part.SetterType = part.LastSetter.GetParameters().Last().ParameterType;
+
+                        if (Binding.AllowChaining)
                         {
-                            MethodInfo setValueMethod = null;
-#if NETSTANDARD1_0
-                            foreach (MethodInfo m in sourceType.AsType().GetRuntimeMethods())
+                            FieldInfo bindablePropertyField = sourceType.GetDeclaredField(part.Content + "Property");
+                            if (bindablePropertyField != null && bindablePropertyField.FieldType == typeof(BindableProperty) && sourceType.ImplementedInterfaces.Contains(typeof(IElementController)))
                             {
-                                if (m.Name.EndsWith("IElementController.SetValueFromRenderer"))
+                                MethodInfo setValueMethod = null;
+#if NETSTANDARD1_0
+                                foreach (MethodInfo m in sourceType.AsType().GetRuntimeMethods())
                                 {
-                                    ParameterInfo[] parameters = m.GetParameters();
-                                    if (parameters.Length == 2 && parameters[0].ParameterType == typeof(BindableProperty))
+                                    if (m.Name.EndsWith("IElementController.SetValueFromRenderer"))
                                     {
-                                        setValueMethod = m;
-                                        break;
+                                        ParameterInfo[] parameters = m.GetParameters();
+                                        if (parameters.Length == 2 && parameters[0].ParameterType == typeof(BindableProperty))
+                                        {
+                                            setValueMethod = m;
+                                            break;
+                                        }
                                     }
                                 }
-                            }
 #else
-                            setValueMethod = typeof(IElementController).GetMethod("SetValueFromRenderer", new[] { typeof(BindableProperty), typeof(object) });
+                                setValueMethod = typeof(IElementController).GetMethod("SetValueFromRenderer", new[] { typeof(BindableProperty), typeof(object) });
 #endif
-                            if (setValueMethod != null)
-                            {
-                                part.LastSetter = setValueMethod;
-                                part.IsBindablePropertySetter = true;
-                                part.BindablePropertyField = bindablePropertyField.GetValue(null);
+                                if (setValueMethod != null)
+                                {
+                                    part.LastSetter = setValueMethod;
+                                    part.IsBindablePropertySetter = true;
+                                    part.BindablePropertyField = bindablePropertyField.GetValue(null);
+                                }
                             }
                         }
                     }
index 73918cb..54f6648 100755 (executable)
@@ -42,7 +42,11 @@ namespace Tizen.NUI.Binding
 
         public int Count
         {
-            get { return _list.Count; }
+            get 
+            {
+                lock (_list)
+                    return _list.Count; 
+            }
         }
 
         bool ICollection<T>.IsReadOnly
@@ -100,12 +104,14 @@ namespace Tizen.NUI.Binding
         {
             get
             {
-                ReadOnlyCollection<T> snap = _snapshot;
-                if (snap != null)
-                    return snap[index];
-
                 lock (_list)
+                {
+                    ReadOnlyCollection<T> snap = _snapshot;
+                    if (snap != null)
+                        return snap[index];
+
                     return _list[index];
+                }
             }
 
             set
index 8fc16b2..b1f804f 100755 (executable)
@@ -212,12 +212,15 @@ namespace Tizen.NUI.Binding
                         try
                         {
                             Assembly refAsm = Assembly.Load(refName);
-                            RegisterAssemblyRecursively(refAsm);
-                            if (refName.Name == "Xamarin.Forms.Core")
+                            if (refAsm != null)
                             {
-                                if (refAsm.GetType("Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement") != null)
+                                RegisterAssemblyRecursively(refAsm);
+                                if (refName.Name == "Xamarin.Forms.Core")
                                 {
-                                    IsTizenSpecificAvailable = true;
+                                    if (refAsm.GetType("Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement") != null)
+                                    {
+                                        IsTizenSpecificAvailable = true;
+                                    }
                                 }
                             }
                         }
index 65e40e7..920a9d5 100755 (executable)
@@ -411,10 +411,10 @@ namespace Tizen.NUI.BaseComponents
         });
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty LeftFocusableViewProperty = BindableProperty.Create("LeftFocusableView", typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
+        public static readonly BindableProperty LeftFocusableViewProperty = BindableProperty.Create(nameof(View.LeftFocusableView), typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
         {
             var view = (View)bindable;
-            if (newValue != null) { view.LeftFocusableViewId = (int)(newValue as View).GetId(); }
+            if (newValue != null) { view.LeftFocusableViewId = (int)(newValue as View)?.GetId(); }
             else { view.LeftFocusableViewId = -1; }
         },
         defaultValueCreator:(bindable) =>
@@ -425,10 +425,10 @@ namespace Tizen.NUI.BaseComponents
         });
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty RightFocusableViewProperty = BindableProperty.Create("RightFocusableView", typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
+        public static readonly BindableProperty RightFocusableViewProperty = BindableProperty.Create(nameof(View.RightFocusableView), typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
         {
             var view = (View)bindable;
-            if (newValue != null) { view.RightFocusableViewId = (int)(newValue as View).GetId(); }
+            if (newValue != null) { view.RightFocusableViewId = (int)(newValue as View)?.GetId(); }
             else { view.RightFocusableViewId = -1; }
         },
         defaultValueCreator:(bindable) =>
@@ -439,10 +439,10 @@ namespace Tizen.NUI.BaseComponents
         });
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty UpFocusableViewProperty = BindableProperty.Create("UpFocusableView", typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
+        public static readonly BindableProperty UpFocusableViewProperty = BindableProperty.Create(nameof(View.UpFocusableView), typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
         {
             var view = (View)bindable;
-            if (newValue != null) { view.UpFocusableViewId = (int)(newValue as View).GetId(); }
+            if (newValue != null) { view.UpFocusableViewId = (int)(newValue as View)?.GetId(); }
             else  { view.UpFocusableViewId = -1; }
         },
         defaultValueCreator:(bindable) =>
@@ -453,10 +453,10 @@ namespace Tizen.NUI.BaseComponents
         });
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty DownFocusableViewProperty = BindableProperty.Create("DownFocusableView", typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
+        public static readonly BindableProperty DownFocusableViewProperty = BindableProperty.Create(nameof(View.DownFocusableView), typeof(View), typeof(View), default(View), propertyChanged: (bindable, oldValue, newValue) =>
         {
             var view = (View)bindable;
-            if (newValue != null) { view.DownFocusableViewId = (int)(newValue as View).GetId(); }
+            if (newValue != null) { view.DownFocusableViewId = (int)(newValue as View)?.GetId(); }
             else { view.DownFocusableViewId = -1; }
         },
         defaultValueCreator:(bindable) =>