Skip to content

Commit

Permalink
SWEEP: Changed all applicable InvalidOperationException creation stat…
Browse files Browse the repository at this point in the history
…ements to IllegalStateException.Create() (see #446).
  • Loading branch information
NightOwl888 committed Apr 26, 2021
1 parent 3e348a3 commit 1df8678
Show file tree
Hide file tree
Showing 115 changed files with 261 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ private FST<CharsRef> ParseConversions(TextReader reader, int num)
}
if (mappings.Put(parts[1], parts[2]) != null)
{
throw new InvalidOperationException("duplicate mapping specified for: " + parts[1]);
throw IllegalStateException.Create("duplicate mapping specified for: " + parts[1]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public override bool IncrementToken()
{
if (!initialized)
{
throw new InvalidOperationException("Consumer did not call reset().");
throw IllegalStateException.Create("Consumer did not call Reset().");
}
if (matcher == null)
{
Expand Down Expand Up @@ -494,7 +494,7 @@ public override bool IncrementToken()
{
if (str == null)
{
throw new InvalidOperationException("Consumer did not call reset().");
throw IllegalStateException.Create("Consumer did not call Reset().");
}
ClearAttributes();
// cache loop instance vars (performance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ internal void AddState(AttributeSource.State state)
{
if (it != null)
{
throw new InvalidOperationException("The tee must be consumed before sinks are consumed.");
throw IllegalStateException.Create("The tee must be consumed before sinks are consumed.");
}
cachedStates.Add(state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public virtual void Execute()
{
if (executed)
{
throw new InvalidOperationException("Benchmark was already executed");
throw IllegalStateException.Create("Benchmark was already executed");
}
executed = true;
runData.SetStartTimeMillis();
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static SpatialStrategy GetSpatialStrategy(int roundNumber)
{
if (!spatialStrategyCache.TryGetValue(roundNumber, out SpatialStrategy result) || result == null)
{
throw new InvalidOperationException("Strategy should have been init'ed by SpatialDocMaker by now");
throw IllegalStateException.Create("Strategy should have been init'ed by SpatialDocMaker by now");
}
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ public virtual void Add(TaskStats stat2)
{
if (countsByTimeStepMSec != stat2.countsByTimeStepMSec)
{
throw new InvalidOperationException("different by-time msec step");
throw IllegalStateException.Create("different by-time msec step");
}
if (countsByTime.Length != stat2.countsByTime.Length)
{
throw new InvalidOperationException("different by-time msec count");
throw IllegalStateException.Create("different by-time msec count");
}
for (int i = 0; i < stat2.countsByTime.Length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override int DoLogic()
}
else
{
throw new InvalidOperationException("TaxonomyWriter is not currently open");
throw IllegalStateException.Create("TaxonomyWriter is not currently open");
}

return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Tasks/ForceMergeTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override int DoLogic()
{
if (maxNumSegments == -1)
{
throw new InvalidOperationException("required argument (maxNumSegments) was not specified");
throw IllegalStateException.Create("required argument (maxNumSegments) was not specified");
}
IndexWriter iw = RunData.IndexWriter;
iw.ForceMerge(maxNumSegments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public override Sort Sort
{
if (sort == null)
{
throw new InvalidOperationException("No sort field was set");
throw IllegalStateException.Create("No sort field was set");
}
return sort;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Tasks/UpdateDocTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override int DoLogic()
string docID = doc.Get(DocMaker.ID_FIELD);
if (docID == null)
{
throw new InvalidOperationException("document must define the docid field");
throw IllegalStateException.Create("document must define the docid field");
}
IndexWriter iw = RunData.IndexWriter;
iw.UpdateDocument(new Term(DocMaker.ID_FIELD, docID), doc);
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public override SeekStatus SeekCeil(BytesRef target)
{
if (indexEnum == null)
{
throw new InvalidOperationException("terms index was not loaded");
throw IllegalStateException.Create("terms index was not loaded");
}

//System.out.println("BTR.seek seg=" + segment + " target=" + fieldInfo.name + ":" + target.utf8ToString() + " " + target + " current=" + term().utf8ToString() + " " + term() + " indexIsCurrent=" + indexIsCurrent + " didIndexNext=" + didIndexNext + " seekPending=" + seekPending + " divisor=" + indexReader.getDivisor() + " this=" + this);
Expand Down Expand Up @@ -827,7 +827,7 @@ public override void SeekExact(long ord)
//System.out.println("BTR.seek by ord ord=" + ord);
if (indexEnum == null)
{
throw new InvalidOperationException("terms index was not loaded");
throw IllegalStateException.Create("terms index was not loaded");
}

if (Debugging.AssertsEnabled) Debugging.Assert(ord < outerInstance.numTerms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public override int NextPosition()
// IndexOutOfRangeException if we didn't, which doesn't really provide good feedback as to what the cause is.
// This matches the behavior of Lucene 8.x. See #267.
if (((_positions != null && _nextPos < _positions.Length) || _startOffsets != null && _nextPos < _startOffsets.Length) == false)
throw new InvalidOperationException("Read past last position");
throw IllegalStateException.Create("Read past last position");

if (_positions != null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Expressions/ExpressionValueSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal ExpressionValueSource(Bindings bindings, Expression expression)
if (source == null)
{
// LUCENENET specific: Changed from RuntimeException to InvalidOperationException to match .NET conventions
throw new InvalidOperationException("Internal error. Variable (" + expression.Variables[i]
throw IllegalStateException.Create("Internal error. Variable (" + expression.Variables[i]
+ ") does not exist.");
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ public override FunctionValues GetValues(IDictionary context, AtomicReaderContex
{
// LUCENENET specific: Changed from RuntimeException to InvalidOperationException to match .NET conventions
#pragma warning disable IDE0016 // Use 'throw' expression
throw new InvalidOperationException($"Internal error. External ({externalName}) does not exist.");
throw IllegalStateException.Create($"Internal error. External ({externalName}) does not exist.");
#pragma warning restore IDE0016 // Use 'throw' expression
}
valuesCache[externalName] = values;
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private Expression CompileExpression()
catch (Exception exception) when (exception.IsInstantiationException() || exception.IsIllegalAccessException() ||
exception.IsNoSuchMethodException() || exception.IsInvocationTargetException())
{
throw new ArgumentException("An internal error occurred attempting to compile the expression (" + sourceText + ").", exception);
throw IllegalStateException.Create("An internal error occurred attempting to compile the expression (" + sourceText + ").", exception);
}
}

Expand Down Expand Up @@ -489,7 +489,7 @@ private void RecursiveCompile(ITree current, Type expected)

default:
{
throw new InvalidOperationException("Unknown operation specified: (" + current.Text + ").");
throw IllegalStateException.Create("Unknown operation specified: (" + current.Text + ").");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Expressions/ScoreValueSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override FunctionValues GetValues(IDictionary context, AtomicReaderContex
Scorer v = (Scorer)context["scorer"];
if (v == null)
{
throw new InvalidOperationException("Expressions referencing the score can only be used for sorting");
throw IllegalStateException.Create("Expressions referencing the score can only be used for sorting");
}
return new ScoreFunctionValues(this, v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void Count(IList<FacetsCollector.MatchingDocs> matchingDocs)
// AIOOBE can happen:
if (!Equals(ReaderUtil.GetTopLevelContext(hits.Context).Reader, origReader))
{
throw new InvalidOperationException("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader");
throw IllegalStateException.Create("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader");
}

SortedSetDocValues segValues = reader.GetSortedSetDocValues(field);
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected override SearcherAndTaxonomy RefreshIfNeeded(SearcherAndTaxonomy @ref)
else if (taxoWriter != null && taxoWriter.TaxonomyEpoch != taxoEpoch)
{
IOUtils.Dispose(newReader, tr);
throw new InvalidOperationException("DirectoryTaxonomyWriter.replaceTaxonomy was called, which is not allowed when using SearcherTaxonomyManager");
throw IllegalStateException.Create("DirectoryTaxonomyWriter.ReplaceTaxonomy() was called, which is not allowed when using SearcherTaxonomyManager");
}

return new SearcherAndTaxonomy(SearcherManager.GetSearcher(searcherFactory, newReader), tr);
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public Entry Next()
Entry e = this.next;
if (e == null)
{
throw new InvalidOperationException(this.GetType() + " cannot get next entry"); ;
throw IllegalStateException.Create(this.GetType() + " cannot get next entry"); ;
}

Entry n = e.next;
Expand Down
10 changes: 5 additions & 5 deletions src/Lucene.Net.Grouping/BlockGroupingCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,30 @@ public override float GetScore()
return score;
}

public override int Freq => throw new InvalidOperationException(); // TODO: wtf does this class do?
public override int Freq => throw IllegalStateException.Create(); // TODO: wtf does this class do?

public override int DocID => doc;

public override int Advance(int target)
{
throw new InvalidOperationException();
throw IllegalStateException.Create();
}

public override int NextDoc()
{
throw new InvalidOperationException();
throw IllegalStateException.Create();
}

public override long GetCost()
{
return 1;
}

public override Weight Weight => throw new InvalidOperationException();
public override Weight Weight => throw IllegalStateException.Create();

public override ICollection<ChildScorer> GetChildren()
{
throw new InvalidOperationException();
throw IllegalStateException.Create();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Grouping/GroupingSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public virtual ITopGroups<object> Search(IndexSearcher searcher, Filter filter,
}
else
{
throw new InvalidOperationException("Either groupField, groupFunction or groupEndDocs must be set."); // This can't happen...
throw IllegalStateException.Create("Either groupField, groupFunction or groupEndDocs must be set."); // This can't happen...
}
}

Expand All @@ -183,7 +183,7 @@ public virtual ITopGroups<TGroupValue> Search<TGroupValue>(IndexSearcher searche
}
else
{
throw new InvalidOperationException("Either groupField, groupFunction or groupEndDocs must be set."); // This can't happen...
throw IllegalStateException.Create("Either groupField, groupFunction or groupEndDocs must be set."); // This can't happen...
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private IDictionary<int, object> HighlightField(string field, string[] contents,
if (fieldFormatter == null)
{
// LUCENENET: Changed from NullPointerException to InvalidOperationException (which isn't caught anywhere outside of tests)
throw new InvalidOperationException("PassageFormatter cannot be null");
throw IllegalStateException.Create("PassageFormatter cannot be null");
}

// check if we should do any multiterm processing
Expand Down Expand Up @@ -612,7 +612,7 @@ private Passage[] HighlightDoc(string field, BytesRef[] terms, int contentLength
if (scorer == null)
{
// LUCENENET: Changed from NullPointerException to InvalidOperationException (which isn't caught anywhere outside of tests)
throw new InvalidOperationException("PassageScorer cannot be null");
throw IllegalStateException.Create("PassageScorer cannot be null");
}
JCG.PriorityQueue<OffsetsEnum> pq = new JCG.PriorityQueue<OffsetsEnum>();
float[] weights = new float[terms.Length];
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Join/ToChildBlockJoinQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override Scorer GetScorer(AtomicReaderContext readerContext, IBits accept
}
if (!(parents is FixedBitSet))
{
throw new InvalidOperationException("parentFilter must return FixedBitSet; got " + parents);
throw IllegalStateException.Create("parentFilter must return FixedBitSet; got " + parents);
}

return new ToChildBlockJoinScorer(this, parentScorer, (FixedBitSet)parents, _doScores, acceptDocs);
Expand Down Expand Up @@ -265,7 +265,7 @@ private void ValidateParentDoc()
{
if (_parentDoc != NO_MORE_DOCS && !_parentBits.Get(_parentDoc))
{
throw new InvalidOperationException(INVALID_QUERY_MESSAGE + _parentDoc);
throw IllegalStateException.Create(INVALID_QUERY_MESSAGE + _parentDoc);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Lucene.Net.Join/ToParentBlockJoinQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public override Scorer GetScorer(AtomicReaderContext readerContext, IBits accept
}
if (!(parents is FixedBitSet))
{
throw new InvalidOperationException("parentFilter must return FixedBitSet; got " + parents);
throw IllegalStateException.Create("parentFilter must return FixedBitSet; got " + parents);
}

return new BlockJoinScorer(this, childScorer, (FixedBitSet)parents, firstChildDoc, scoreMode, acceptDocs);
Expand Down Expand Up @@ -245,7 +245,7 @@ internal virtual float[] SwapChildScores(float[] other)
{
if (_scoreMode == ScoreMode.None)
{
throw new InvalidOperationException("ScoreMode is None; you must pass trackScores=false to ToParentBlockJoinCollector");
throw IllegalStateException.Create("ScoreMode is None; you must pass trackScores=false to ToParentBlockJoinCollector");
}
float[] ret = _pendingChildScores;
if (other == null)
Expand Down Expand Up @@ -280,7 +280,7 @@ public override int NextDoc()
// orthogonal:
if (_nextChildDoc == _parentDoc)
{
throw new InvalidOperationException("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
throw IllegalStateException.Create("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
}

//System.out.println(" parentDoc=" + parentDoc);
Expand All @@ -300,7 +300,7 @@ public override int NextDoc()
// orthogonal:
if (_nextChildDoc == _parentDoc)
{
throw new InvalidOperationException("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
throw IllegalStateException.Create("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
}

continue;
Expand Down Expand Up @@ -347,7 +347,7 @@ public override int NextDoc()
// orthogonal:
if (_nextChildDoc == _parentDoc)
{
throw new InvalidOperationException("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
throw IllegalStateException.Create("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
}

switch (_scoreMode)
Expand Down Expand Up @@ -414,7 +414,7 @@ public override int Advance(int parentTarget)
// Parent & child docs are supposed to be orthogonal:
if (_nextChildDoc == _prevParentDoc)
{
throw new InvalidOperationException("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
throw IllegalStateException.Create("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
}

int nd = NextDoc();
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Misc/Document/LazyDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal virtual Document GetDocument()
}
catch (Exception ioe) when (ioe.IsIOException())
{
throw new InvalidOperationException("unable to load document", ioe);
throw IllegalStateException.Create("unable to load document", ioe);
}
}
return doc;
Expand Down
Loading

0 comments on commit 1df8678

Please sign in to comment.