[Mono-bugs] [Bug 507120] New: GetListItemType throws NullReferenceException when dataSource's type is DataViewManager
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Tue May 26 10:11:35 EDT 2009
http://bugzilla.novell.com/show_bug.cgi?id=507120
Summary: GetListItemType throws NullReferenceException when
dataSource's type is DataViewManager
Classification: Mono
Product: Mono: Class Libraries
Version: 2.4.x
Platform: i686
OS/Version: openSUSE 11.1
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Windows.Forms
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: p.ricca at odyssee-ingenierie.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Created an attachment (id=294466)
--> (http://bugzilla.novell.com/attachment.cgi?id=294466)
backtrace of debug mode
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10)
Gecko/2009042700 SUSE/3.0.10-1.1.1 Firefox/3.0.10
Hello,
In the function GetListItemType(object dataSource, string dataMember) of
System.Windows.Forms/ListBondingHelper.cs, our program crashed with
NullReferenceException, when dataSource's type is DataViewManager .
We had localized the piece of code where the Exception is thrown :
if (dataSource is IEnumerable) {
IEnumerator enumerator = ((IEnumerable) dataSource).GetEnumerator ();
if (enumerator.MoveNext ()){
'the execution goes here, and crahes
return enumerator.Current.GetType (); ' (1)
}
if (dataSource is IList || dataSource.GetType () == typeof (IList<>)) {
PropertyInfo property = GetPropertyByReflection (dataSource.GetType (),
"Item");
return property.PropertyType; '(2)
}
// fallback to object
return typeof (object);
}
After having tested, we found that it was because of enumerator.Current (1)
which is null. If we check before returning that enumerator.Current is not null
at (1) , we have another NullRefenceException at (2) because of property.
Finally, we have modified this piece of code by the following one :
if (dataSource is IEnumerable) {
IEnumerator enumerator = ((IEnumerable) dataSource).GetEnumerator ();
if (enumerator.MoveNext ()){
if (enumerator.Current != null)
return enumerator.Current.GetType ();
}
if (dataSource is IList || dataSource.GetType () == typeof (IList<>)) {
PropertyInfo property = GetPropertyByReflection (dataSource.GetType (),
"Item");
if (property != null)
return property.PropertyType;
}
// fallback to object
return typeof (object);
}
If it can help you, you will find enclosed the backtrace of the debug mode.
Thank you in advance, do not hesitate to ask for precisions if necessary .
Reproducible: Always
Steps to Reproduce:
1.
2.
3.
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list