Author: alanmc
Date: 2008-02-19 17:35:58 -0500 (Tue, 19 Feb 2008)
New Revision: 96201

Modified:
   trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Tracker/TrackerFactory.cs
Log:
Added null checks

Modified: 
trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Tracker/TrackerFactory.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Tracker/TrackerFactory.cs 
2008-02-19 22:29:29 UTC (rev 96200)
+++ trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Tracker/TrackerFactory.cs 
2008-02-19 22:35:58 UTC (rev 96201)
@@ -41,18 +41,27 @@
 
         public static void Register(string protocol, Type trackerType)
         {
+            if (string.IsNullOrEmpty(protocol))
+                throw new ArgumentException("cannot be null or empty", 
protocol);
+            if (trackerType == null)
+                throw new ArgumentNullException("trackerType");
+
             lock (locker)
                 trackerTypes.Add(protocol, trackerType);
         }
 
         public static Tracker Create(string protocol, Uri announceUrl)
         {
-            Type type;
-            lock (locker)
-                if (!trackerTypes.TryGetValue(protocol, out type))
-                    return null;
+            if (string.IsNullOrEmpty(protocol))
+                throw new ArgumentException("cannot be null or empty", 
"protocol");
 
-            return (Tracker)Activator.CreateInstance(type, announceUrl);
+            if (announceUrl == null)
+                throw new ArgumentNullException("announceUrl");
+
+            if (!trackerTypes.ContainsKey(protocol))
+                return null;
+
+            return (Tracker)Activator.CreateInstance(trackerTypes[protocol], 
announceUrl);
         }
     }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to