[Mono-bugs] [Bug 81834][Nor] New - System.String.Format should make null object ""
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Fri Jun 8 14:46:41 EDT 2007
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 vgiszpenc at dsci.com.
http://bugzilla.ximian.com/show_bug.cgi?id=81834
--- shadow/81834 2007-06-08 14:46:41.000000000 -0400
+++ shadow/81834.tmp.7180 2007-06-08 14:46:41.000000000 -0400
@@ -0,0 +1,96 @@
+Bug#: 81834
+Product: Mono: Class Libraries
+Version: 1.2
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: vgiszpenc at dsci.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: System.String.Format should make null object ""
+
+Description of Problem:
+If you call System.String.Format and pass a valid format string and a null
+object, you should NOT get an exception according to Microsoft
+
+Copied from MSDN
+
+ index
+
+ A zero-based integer that indicates which element in a list of objects
+to format. If the object specified by index is a null reference (Nothing in
+Visual Basic), then the format item is replaced by the empty string ("").
+
+I noticed that StringBuilder has the same issue but uses different code to
+do similar stuff.
+
+
+Steps to reproduce the problem:
+class Test
+{
+ static void Main()
+ {
+ System.Console.WriteLine("Null object {0}", null);
+ }
+}
+
+class Test2
+{
+ static void Main()
+ {
+ System.Text.StringBuilder sb = new System.Text.StringBuilder();
+ sb.AppendFormat("Null test2 {0}", null);
+ System.Console.WriteLine(sb.ToString());
+ }
+}
+Actual Results:
+
+Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
+ at System.String.FormatHelper (System.Text.StringBuilder result,
+IFormatProvider provider, System.String format, System.Object[] args) [0x00000]
+ at System.String.Format (IFormatProvider provider, System.String format,
+System.Object[] args) [0x00000]
+ at System.String.Format (System.String format, System.Object[] args)
+[0x00000]
+ at System.IO.TextWriter.Write (System.String format, System.Object[] arg)
+[0x00000]
+ at System.IO.TextWriter.WriteLine (System.String format, System.Object[]
+arg) [0x00000]
+ at System.Console.WriteLine (System.String format, System.Object[] arg)
+[0x00000]
+ at Test.Main () [0x00000]
+
+
+*** TEST 2 Result ***
+
+Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
+ at System.String.FormatHelper (System.Text.StringBuilder result,
+IFormatProvider provider, System.String format, System.Object[] args) [0x00000]
+ at System.Text.StringBuilder.AppendFormat (IFormatProvider provider,
+System.String format, System.Object[] args) [0x00000]
+ at System.Text.StringBuilder.AppendFormat (System.String format,
+System.Object[] args) [0x00000]
+ at Test.Main () [0x00000]
+
+
+
+Expected Results:
+Null object
+
+Null test2
+
+How often does this happen?
+Always
+
+Additional Information:
+There may be other places that do formatting. I am not familiar enough
+with .Net to say that this pattern is only in String and StringBuilder.
+
+Thanks!
More information about the mono-bugs
mailing list