[Mono-bugs] [Bug 71669][Nor] New - NullPointerException when setting a value-type field to null through reflection
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 24 Jan 2005 10:23:32 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by serko84@hotmail.com.
http://bugzilla.ximian.com/show_bug.cgi?id=71669
--- shadow/71669 2005-01-24 10:23:32.000000000 -0500
+++ shadow/71669.tmp.13894 2005-01-24 10:23:32.000000000 -0500
@@ -0,0 +1,69 @@
+Bug#: 71669
+Product: Mono: Class Libraries
+Version: 1.0
+OS: Debian Woody
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: serko84@hotmail.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: NullPointerException when setting a value-type field to null through reflection
+
+Description of Problem:
+When setting a field of a value type to null using reflection, a NPE is
+thrown. On Microsoft .NET the value is set to its default.
+
+Steps to reproduce the problem:
+ class OneDecimal
+ {
+ public decimal d;
+ };
+
+ [Test]
+ public void Test()
+ {
+ OneDecimal od = new OneDecimal();
+ od.d = 10.0m;
+
+ FieldInfo fi = typeof(OneDecimal).GetField("d",
+ BindingFlags.Instance | BindingFlags.Public);
+
+ Assert.IsNotNull(fi);
+ fi.SetValue(od, null);
+
+ Assert.AreEqual(od.d, 0.0m);
+ }
+
+Actual Results:
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+in (unmanaged) (wrapper managed-to-native)
+System.Reflection.MonoField:SetValueInternal
+(System.Reflection.FieldInfo,object,object)
+in <0x00004> (wrapper managed-to-native)
+System.Reflection.MonoField:SetValueInternal
+(System.Reflection.FieldInfo,object,object)
+in <0x000c9> System.Reflection.MonoField:SetValue
+(object,object,System.Reflection.BindingFlags,System.Reflection.Binder,System.Globalization.CultureInfo)
+in <0x00020> System.Reflection.FieldInfo:SetValue (object,object)
+in <0x0010c> X:Main ()
+
+(the last line is X:Main because I ran a slightly different version of the
+test as a stand-alone program)
+
+Expected Results:
+The test should pass
+
+How often does this happen?
+When the field type is a value type.
+
+Additional Information:
+I'm using Mono 1.0.5 built from source on Debian testing.