[Mono-bugs] [Bug 481621] NRE thrown when trying to remove null element (not null LinkedListNode element)
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Mar 9 05:35:20 EDT 2009
https://bugzilla.novell.com/show_bug.cgi?id=481621
User andyhume32 at yahoo.co.uk added comment
https://bugzilla.novell.com/show_bug.cgi?id=481621#c2
Andy Hume <andyhume32 at yahoo.co.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andyhume32 at yahoo.co.uk
--- Comment #2 from Andy Hume <andyhume32 at yahoo.co.uk> 2009-03-09 03:35:19 MST ---
But (T)null is a valid value to add, so it's a valid value to remove as well,
see test below. So the fix should instead be something like the following.
Are there a pile more tests needed however?
[[
--- D:\Temp\LinkedList.cs-revBASE.svn001.tmp.cs Mon Mar 9 09:28:13 2009
+++
D:\cygwin\usr\src\mono\mcs\class\System\System.Collections.Generic\LinkedList.cs
Mon Mar 9 09:25:59 2009
@@ -235,7 +235,7 @@
return null;
do
{
- if ( (value == null && node.Value == null) || value.Equals
(node.Value))
+ if ( (value == null && node.Value == null) || (value != null
&& value.Equals (node.Value)))
return node;
node = node.forward;
}
]]
[[
using System;
using System.Collections.Generic;
class LinkedListAddRemoveNull {
static int Main()
{
Play();
return Test();
}
static int Test()
{
LinkedList <object> l = new LinkedList<object> ();
l.AddLast ((object)null);
bool success = l.Remove ((object)null);
Console.WriteLine (success.ToString());
return success ? 1 : 0;
}
static void Play()
{
var li = new LinkedList<string> ();
li.AddLast((string)null);
li.AddLast("abcd");
li.AddLast((string)null);
li.AddLast("efgh");
Dump(li);
Console.WriteLine();
PrintBoolean(
li.Remove((string)null));
Dump(li);
Console.WriteLine();
PrintBoolean(
li.Remove((string)null));
Dump(li);
Console.WriteLine();
PrintBoolean(
li.Remove((string)null));
Dump(li);
Console.WriteLine();
}
static void PrintBoolean(bool value)
{
Console.WriteLine("bool = {0}", value);
}
static void Dump(System.Collections.IEnumerable eable)
{
foreach (object cur in eable) {
if (cur == null)
Console.Write("(null), ");
else
Console.Write("'{0}', ", cur);
}
Console.WriteLine();
}
}
]]
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list