I just got a phone call from an RSS Bandit user whose daily workflow had been derailed by a bug in the application. It seems that we were crashing with an ArgumentException stating "Argument already exists in collection" when she tried to import an OPML file. This seemed weird because I always make sure to check if a feed URL exists in the table of currently subscribed URIs before adding it. Looking at the code made me even more confused
if(!_feedsTable.ContainsKey(f1.link)){
f1.lastretrievedSpecified = true;
f1.lastretrieved = dta[count % dtaCount];
_feedsTable.Add(f1.link, f1); /* exception thrown here */
}
So I looked at the implementations of the ContainsKey() and Add() in my data structure which lead me to the conclusion that we need better unit tests
public virtual bool ContainsKey(String key) {
return (IndexOfKey(key) >= 0);
}
public virtual void Add(String key, feedsFeed value) {
if ((object) key == null)
throw new ArgumentNullException("key");
/* convert the URI to a canonicalized absolute URI */
try{
Uri uri = new Uri(key);
key = uri.AbsoluteUri;
value.link = key;
}catch {}
int index = IndexOfKey(key);
if (index >= 0)
throw new ArgumentException(
"Argument already exists in collection.", "key");
Insert(~index, key, value);
}
My apologies to any of our users who have been hit by this problem. It'll be fixed in the final release of Jubilee.