diff options
author | Gert Driesen <drieseng@users.sourceforge.net> | 2009-06-06 21:07:34 +0400 |
---|---|---|
committer | Gert Driesen <drieseng@users.sourceforge.net> | 2009-06-06 21:07:34 +0400 |
commit | 3ee30c68d12c8989ea663fcbe294b8b21742abb8 (patch) | |
tree | 8e6a2323fd8617639d4ed362ecd388727a4c2229 /mcs/class/System/System.ComponentModel.Design.Serialization | |
parent | bf070eecb16eae2d70844b7e182073a571a0b2c0 (diff) |
* ContextStack.cs: Added argument check to Type indexer, avoiding a
NRE. Modify System.Int32 indexer to throw ArgumentOutOfRangeException
instead of ArgumentException. Reduce number of times that item count
must be obtained.
* ContextStackTest.cs: Added unit tests for indexers, and argument
(null) checks.
svn path=/trunk/mcs/; revision=135596
Diffstat (limited to 'mcs/class/System/System.ComponentModel.Design.Serialization')
-rwxr-xr-x | mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog | 7 | ||||
-rw-r--r--[-rwxr-xr-x] | mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs | 36 |
2 files changed, 28 insertions, 15 deletions
diff --git a/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog b/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog index 3f705c8cadc..3d9e9f98d35 100755 --- a/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog +++ b/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog @@ -1,3 +1,10 @@ +2009-06-06 Gert Driesen <drieseng@users.sourceforge.net> + + * ContextStack.cs: Added argument check to Type indexer, avoiding a + NRE. Modify System.Int32 indexer to throw ArgumentOutOfRangeException + instead of ArgumentException. Reduce number of times that item count + must be obtained. + 2008-06-05 Ivan N. Zlatev <contact@i-nz.net> * ContextStack.cs: Also check for subclasses in the Type-based diff --git a/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs b/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs index 132e28447c8..31b238c969b 100755..100644 --- a/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs +++ b/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs @@ -47,18 +47,23 @@ namespace System.ComponentModel.Design.Serialization } public object Current { - get { - if (_contextList.Count > 0) - return _contextList[_contextList.Count-1]; + get { + int context_count = _contextList.Count; + if (context_count > 0) + return _contextList [context_count - 1]; return null; } } public object this[Type type] { get { - for (int i = _contextList.Count - 1; i >= 0; i--) - if (type.IsInstanceOfType (_contextList[i])) - return _contextList[i]; + if (type == null) + throw new ArgumentNullException ("type"); + for (int i = _contextList.Count - 1; i >= 0; i--) { + object context = _contextList [i]; + if (type.IsInstanceOfType (context)) + return context; + } return null; } } @@ -66,9 +71,10 @@ namespace System.ComponentModel.Design.Serialization public object this[int level] { get { if (level < 0) - throw new ArgumentException ("level has to be >= 0","level"); - if (_contextList.Count > 0 && _contextList.Count > level) - return _contextList[_contextList.Count - 1 - level]; + throw new ArgumentOutOfRangeException ("level"); + int context_count = _contextList.Count; + if (context_count > 0 && context_count > level) + return _contextList [context_count - 1 - level]; return null; } } @@ -76,11 +82,12 @@ namespace System.ComponentModel.Design.Serialization public object Pop () { object o = null; - if (_contextList.Count > 0) { - int lastItem = _contextList.Count - 1; - o = _contextList[lastItem]; - _contextList.RemoveAt (lastItem); - } + int context_count = _contextList.Count; + if (context_count > 0) { + int lastItem = context_count - 1; + o = _contextList [lastItem]; + _contextList.RemoveAt (lastItem); + } return o; } @@ -88,7 +95,6 @@ namespace System.ComponentModel.Design.Serialization { if (context == null) throw new ArgumentNullException ("context"); - _contextList.Add (context); } |