[Mono-dev] System.Type.GetTypeCode null arg failure

Mike Welham mwelham at gmail.com
Wed Oct 12 13:07:10 EDT 2005


I tried repeatedly to file this in bugzilla, but she was having none of it.

Description of Problem:
-----------------------

System.Type.GetTypeCode(Type) throws a NullRef exception when its arg is 
null. Microsoft's implementation returns TypeCode.Empty

Steps to reproduce the problem:
-------------------------------

using System;
public class TestHost {
	static void Main() {
		if(Type.GetTypeCode(null) != TypeCode.Empty)
			throw new Exception();
	}
}

Actual Results:
---------------

NullReferenceException thrown

Expected Results:
-----------------

TypeCode.Empty returned

How often does this happen?
---------------------------

Always

Additional Information:
-----------------------

-- patch --

Index: class/corlib/System/Type.cs
===================================================================
--- class/corlib/System/Type.cs (revision 51657)
+++ class/corlib/System/Type.cs (working copy)
@@ -468,6 +468,9 @@
                 internal extern static TypeCode GetTypeCodeInternal 
(Type type);

                 public static TypeCode GetTypeCode (Type type) {
+                       if(type == null)
+                               return TypeCode.Empty;
+
                         type = type.UnderlyingSystemType;

                         if (!type.IsSystemType)

-- end patch --


Mike



More information about the Mono-devel-list mailing list