[Mono-devel-list] [PATCH] Fix null reference exceptions in System.Data.DataView
Konstantin Triger
kostat at mainsoft.com
Wed Jul 6 08:03:58 EDT 2005
Hello Marc,
My view that a problem is deeper: probably we run into a situation where
the DataView is not functional when it should be. Replacing the
assignment of rowCache to an empty array will prevent throwing an
exception, but will not solve the logical problem.
Please open a bugzilla bug with a test case and a patch attached.
Regards,
Konstantin Triger
Marc Haisenko wrote:
>Hi folks,
>I just noticed that a bug in DataView.cs is still/again present in the current
>revision (r46988, svn://svn.myrealbox.com/source/trunk/mcs/)
>
>The problem is that a variable, rowCache, is often set to null but no null
>checks are done. That way a fresh instance of DataView throws a
>NullReferenceException e.g. when reading the Count property as it simply does
>"return rowCache.Length;".
>
>The fix is to never set the variable to null but to an empty array. The
>attached patch implements this fix (only three lines need that fix). I
>already sent a patch to fix the very same bug on 11.11.2004, it seems like it
>never got included...
>
>C'ya,
> Marc
>
>
>
>------------------------------------------------------------------------
>
>Index: DataView.cs
>===================================================================
>--- DataView.cs (revision 46985)
>+++ DataView.cs (working copy)
>@@ -41,7 +41,7 @@
> IExpression rowFilterExpr;
> string sort = String.Empty;
> protected DataViewRowState rowState;
>- protected DataRowView[] rowCache = null;
>+ protected DataRowView[] rowCache = new DataRowView[0];
>
> // BeginInit() support
> bool isInitPhase = false;
>@@ -535,7 +535,7 @@
> if (dataTable != null)
> UnregisterEventHandlers ();
> Index = null;
>- rowCache = null;
>+ rowCache = new DataRowView[0];
> isOpen = false;
> }
>
>@@ -703,7 +703,7 @@
> {
> // TODO: what really happens?
> Close ();
>- rowCache = null;
>+ rowCache = new DataRowView[0];
> Open ();
> OnListChanged (new ListChangedEventArgs (ListChangedType.Reset, -1 ));
> }
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Mono-devel-list mailing list
>Mono-devel-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
More information about the Mono-devel-list
mailing list