[Mono-bugs] [Bug 32416][Nor] New - NullReferenceException in for-statement

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
16 Oct 2002 23:36:41 -0000


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 mathias.hasselmann@gmx.de.

http://bugzilla.ximian.com/show_bug.cgi?id=32416

--- shadow/32416	Wed Oct 16 19:36:41 2002
+++ shadow/32416.tmp.17247	Wed Oct 16 19:36:41 2002
@@ -0,0 +1,48 @@
+Bug#: 32416
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mathias.hasselmann@gmx.de               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: NullReferenceException in for-statement
+
+The for-statement can cause a NullReferenceException if the variable used
+in the abort condition is declared in the initialization portion of the for
+statement.
+
+
+Steps to reproduce the problem:
+public class foo
+{
+    public static void Main()
+    {
+        for (string line; null != (line = System.Console.ReadLine()); )
+            System.Console.WriteLine(line);
+    }
+}
+
+Actual Results:
+NullReferenceException is thrown
+
+Expected Results:
+A C# version of cat.
+
+How often does this happen? 
+Always.
+
+Additional Information:
+
+If line is declared before the for-statement everything works:
+
+string line;
+for(; null != (line = System.Console.ReadLine()); )