[Mono-bugs] [Bug 483985] New: Wrong behavior of generic SortedList compared to .Net behavior

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Mar 10 12:39:01 EDT 2009


https://bugzilla.novell.com/show_bug.cgi?id=483985


           Summary: Wrong behavior of generic SortedList compared to .Net
                    behavior
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: tquerci at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; it; rv:1.9.0.7)
Gecko/2009022800 SUSE/3.0.7-1.2 Firefox/3.0.7

Hi,

the behavior of generic SortedList between .Net and Mono are different.
In depth when you use enumerator from Keys and Values you are able to remove an
element from the sorted list and go on in the enumerator without have any
exception. Moreover you not able to reset the enumerator where is possible on
Net.

THis behavior is tested on VS C# Express

Changes on UnitTest are also provided.



Reproducible: Always

Steps to Reproduce:
// This code show the bug
// The only exception that need to be generated is capture.
// If you run this application without fix you got a uncaptured exception
//
using System;
using System.Collections.Generic;

namespace SortedListTest
{
    class Program
    {
        static void Main(string[] args)
        {
            SortedList<String, String> contents = new SortedList<string,
string>();
            int i;

            contents.Add("key 01", "key 01");
            contents.Add("key 02", "key 02");
            contents.Add("key 03", "key 03");
            contents.Add("key 04", "key 04");
            contents.Add("key 05", "key 05");
            contents.Add("key 06", "key 06");
            contents.Add("key 07", "key 07");
            contents.Add("key 08", "key 08");
            contents.Add("key 09", "key 09");
            contents.Add("key 10", "key 10");

            IEnumerator<string> en = contents.Keys.GetEnumerator();
            string key;
            System.Console.Out.WriteLine("CHECK FOR REMOVE KEY IN THE
SortedList----------------");
            try
            {

                i = 0;
                while (en.MoveNext())
                {
                    key = en.Current;
                    System.Console.Out.Write("Key=" + key);
                    if (i == 4)
                    {
                        contents.Remove(key);
                        System.Console.Out.Write("\tdeleted");
                    }

                    System.Console.Out.WriteLine("");
                    i++;
                }
            }
            catch (Exception ex)
            {
                System.Console.Out.WriteLine("Exception:
"+ex.GetType().ToString()+" - "+ex.Message);
            }

            System.Console.Out.WriteLine("");
            System.Console.Out.WriteLine("CHECK FOR RESET KEY ENUMERATOR IN THE
SortedList----------------");
            en = contents.Keys.GetEnumerator();
            i=0;
            while (en.MoveNext())
            {
                key = en.Current;
                System.Console.Out.WriteLine("Key=" + key+" present");
                if (i==4) {
                    en.Reset();
                }
                i++;
            }

            IEnumerator<string> env = contents.Values.GetEnumerator();
            string val;
           
System.Console.Out.WriteLine("========================================================");
            System.Console.Out.WriteLine("CHECK FOR REMOVE VALUE IN THE
SortedList----------------");
            try
            {

                i = 0;
                while (env.MoveNext())
                {
                    val = env.Current;
                    System.Console.Out.Write("Value=" + val);
                    if (i == 4)
                    {
                        contents.RemoveAt(i);
                        System.Console.Out.Write("\tdeleted");
                    }

                    System.Console.Out.WriteLine("");
                    i++;
                }
            }
            catch (Exception ex)
            {
                System.Console.Out.WriteLine("Exception:
"+ex.GetType().ToString()+" - "+ex.Message);
            }

            System.Console.Out.WriteLine("");
            System.Console.Out.WriteLine("CHECK FOR RESET VALUE ENUMERATOR IN
THE SortedList----------------");
            env = contents.Keys.GetEnumerator();
            i=0;
            while (env.MoveNext())
            {
                val = env.Current;
                System.Console.Out.WriteLine("value=" + val+" present");
                if (i==4) {
                    env.Reset();
                }
                i++;
            }

            System.Console.In.ReadLine();
        }
    }
}

-- 
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