[Mono-bugs] [Bug 55573][Nor] New - Match.Groups[x] object is null where x is higher than the number of matches.

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sun, 14 Mar 2004 16:09:53 -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 m.sibson@warwick.ac.uk.

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

--- shadow/55573	2004-03-14 16:09:53.000000000 -0500
+++ shadow/55573.tmp.14121	2004-03-14 16:09:53.000000000 -0500
@@ -0,0 +1,48 @@
+Bug#: 55573
+Product: Mono: Class Libraries
+Version: unspecified
+OS: other
+OS Details: Debian Sid
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: m.sibson@warwick.ac.uk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Match.Groups[x] object is null where x is higher than the number of matches.
+
+Description of Problem:
+Match.Groups[x] returns 'null' rather than an empty object when 'x' is
+outside the bounds of the number of matches and results on a null exception
+when, for example, performing Match.Groups[x].ToString(). This behaviour is
+not consistent with the Microsoft runtime.
+
+Steps to reproduce the problem:
+
+// This is the regex to match
+Regex qualifier = new Regex(@"^(.+)[,][\s]*(\S+)[\s]*(.*)");
+
+// If message does not match the regex, some, or
+// all groups will be left empty
+Match messageLine = qualifier.Match(message);
+
+// This leads to one of the following generating NullReference
+string address = messageLine.Groups[1].ToString();
+string command = messageLine.Groups[2].ToString();
+string arguments = messageLine.Groups[3].ToString();
+
+The issue here is non-consistancy, rather than my bad programming.
+
+Actual Results (Under Mono):
+System.NullReferenceException
+
+
+Expected Results (Under MS):
+Strings contain "", a zero length string.
+
+Using version 30.2