[system.data] DataRows with a NULL RowError incorrectly indicated HasError:
authorMatthew Leibowitz <mattleibow@live.com>
Mon, 1 Sep 2014 18:03:03 +0000 (11:03 -0700)
committerMatthew Leibowitz <mattleibow@live.com>
Mon, 1 Sep 2014 18:03:03 +0000 (11:03 -0700)
 - MS.NET allows RowError to be set to NULL, but will convert it to string.Empty

mcs/class/System.Data/System.Data/DataRow.cs
mcs/class/System.Data/Test/System.Data/DataRowTest2.cs

index 4207d16f878dbb43dea2f68edd7005a150ecf654..2d0df625f37bf7cbec2ba369d04a77211a4b7f20 100644 (file)
@@ -118,11 +118,11 @@ namespace System.Data {
                /// </summary>
                public bool HasErrors {
                        get {
-                               if (RowError != string.Empty)
+                               if (!string.IsNullOrEmpty (RowError))
                                        return true;
 
                                foreach (String columnError in ColumnErrors) {
-                                       if (columnError != null && columnError != string.Empty)
+                                       if (!string.IsNullOrEmpty (columnError))
                                                return true;
                                }
                                return false;
@@ -509,7 +509,7 @@ namespace System.Data {
                /// </summary>
                public string RowError {
                        get { return rowError; }
-                       set { rowError = value; }
+                       set { rowError = value ?? string.Empty; }
                }
 
                internal int IndexFromVersion (DataRowVersion version)
index 4dc0d77495e8178801e83aa7ce4f0c293605bcc5..e3e7aac2857d0066399af79ba1f24b20f26f721d 100644 (file)
@@ -739,6 +739,21 @@ namespace MonoTests.System.Data
                        Assert.AreEqual(true , dr.HasErrors , "DRW48");
                }
 
+               [Test] public void HasErrorsWithNullError()
+               {
+                       DataTable dt = new DataTable("myTable"); 
+                       DataRow dr = dt.NewRow();
+
+                       // HasErrors (default)
+                       Assert.AreEqual(false, dr.HasErrors, "DRW47.2");
+
+                       dr.RowError = null;
+
+                       // HasErrors (set/get)
+                       Assert.AreEqual(string.Empty , dr.RowError , "DRW48.2");
+                       Assert.AreEqual(false , dr.HasErrors , "DRW49.2");
+               }
+
                [Test] public void HasVersion_ByDataRowVersion()
                {
                        DataTable t = new DataTable("atable");