Challenge: This code should never hit production
Join the DZone community and get the full member experience.
Join For FreeThis 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.
Production (computer science)
Opinions expressed by DZone contributors are their own.
Trending
-
Exploratory Testing Tutorial: A Comprehensive Guide With Examples and Best Practices
-
Top 10 Engineering KPIs Technical Leaders Should Know
-
SRE vs. DevOps
-
How To Use Pandas and Matplotlib To Perform EDA In Python
Comments