Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Challenge: This code should never hit production

DZone's Guide to

Challenge: This code should never hit production

·
Free Resource

This code should never have the chance to go to production, it is horribly broken in a rather subtle way, do you see it?

public ISet<string> GetTerms(string index, string field)
{
if(field == null) throw new ArgumentNullException("field");
if(index == null) throw new ArgumentNullException("index");

var result = new HashSet<string>();
var currentIndexSearcher = database.IndexStorage.GetCurrentIndexSearcher(index);
IndexSearcher searcher;
using(currentIndexSearcher.Use(out searcher))
{
var termEnum = searcher.GetIndexReader().Terms(new Term(field));
while (field.Equals(termEnum.Term().Field()))
{
result.Add(termEnum.Term().Text());

if (termEnum.Next() == false)
break;
}
}

return result;
}


As usual, I’ll post the answer tomorrow.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}