[Mono-bugs] [Bug 605340] New: Unexpected exception on calling String.LastIndexOf on empty strings with startIndex=-1
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed May 12 16:28:06 EDT 2010
http://bugzilla.novell.com/show_bug.cgi?id=605340
http://bugzilla.novell.com/show_bug.cgi?id=605340#c0
Summary: Unexpected exception on calling String.LastIndexOf on
empty strings with startIndex=-1
Classification: Mono
Product: Mono: Class Libraries
Version: SVN
Platform: All
OS/Version: All
Status: NEW
Severity: Normal
Priority: P5 - None
Component: CORLIB
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: lorenz.schwittmann at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.3)
Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3
I just encountered a reproducible crash in an application which runs fine on
Microsoft's .NET. After some debugging, I isolated the problem in the following
call:
String str = "";
str.LastIndexOf('.', -1);
Microsoft's documentation
(http://msdn.microsoft.com/en-us/library/1tw91fa3%28v=VS.100%29.aspx) says, the
method will throw an exception if the second parameter is greater than
this.Length. However, there seems to be a check at the top of the function
which returns -1 if this.Length ==0. No exception is thrown in their
implementation.
Reproducible: Always
Steps to Reproduce:
1. Compile a test application which contains "".LastIndexOf('.', -1);
2. Run application on both mono and MS .NET
Actual Results:
The application crashes only on mono.
Expected Results:
The application shouldn't crash.
Although MS lies in their specs, mono's goal should be to be as close as
possible to their implementation. Otherwise the "write once, run everywhere"
argument is invalid.
I've found a similar bug report
(https://bugzilla.novell.com/show_bug.cgi?id=486234) which deals with an
overloaded version of String.LastIndexOf. However, the committed fix does only
care about calls with startIndex == 0.
I have verified that there is no exception on calling on an empty string with
startIndex=-1 for the following signatures:
String.LastIndexOf(String, Int32)
String.LastIndexOf(Char, Int32, Int32)
String.LastIndexOf(String, Int32, Int32)
String.LastIndexOf(String, Int32, StringComparison)
String.LastIndexOf(String, Int32, Int32, StringComparison)
I suggest to fix ALL of them: If the string is empty, return -1. No matter what
other arguments are passed.
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list