[Mono-bugs] [Bug 395904] New: StringBuilder.ToString(int, int) assumes that String. Substring always creates a new object

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri May 30 12:47:45 EDT 2008


           Summary: StringBuilder.ToString(int, int) assumes that
                    String.Substring always creates a new object
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: juraj at hotfeet.ch
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

Created an attachment (id=219223)
 --> (https://bugzilla.novell.com/attachment.cgi?id=219223)
minimal test case

This bug in StringBuilder is the reason why this code in String.Substring is

// FIXME: this causes regressions in System.Xml
if (startIndex == 0 && length == this.length)
   return this;

To expose the bug:

- enable the code above, "make install PROFILE=net_2_0" in mcs/class/corlib
- compile and run the attached test case

Expected output: none
Actual output:   "Immutable string was changed!"

The source of the problem is that StringBuilder.ToString(int, int) implicitly
assumes that String.Substring will _always create a new string object_. With
the code above enabled, this is no longer the case.

In my opinion, we should add an internal method (e.g. "CopySubstring") to
String which is guaranteed to always create a new string object and call that
one from StringBuilder.ToString(int, int).

Configure bugmail: https://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