From 1df867859d7c5e097a9bbc80145842bca053e8f9 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Fri, 23 Apr 2021 11:41:21 +0700 Subject: [PATCH] SWEEP: Changed all applicable InvalidOperationException creation statements to IllegalStateException.Create() (see #446). --- .../Analysis/Hunspell/Dictionary.cs | 2 +- .../Analysis/Miscellaneous/PatternAnalyzer.cs | 4 ++-- .../Analysis/Sinks/TeeSinkTokenFilter.cs | 2 +- src/Lucene.Net.Benchmark/ByTask/Benchmark.cs | 2 +- .../ByTask/Feeds/SpatialDocMaker.cs | 2 +- .../ByTask/Stats/TaskStats.cs | 4 ++-- .../ByTask/Tasks/CommitTaxonomyIndexTask.cs | 2 +- .../ByTask/Tasks/ForceMergeTask.cs | 2 +- .../ByTask/Tasks/SearchWithSortTask.cs | 2 +- .../ByTask/Tasks/UpdateDocTask.cs | 2 +- .../BlockTerms/BlockTermsReader.cs | 4 ++-- .../SimpleText/SimpleTextTermVectorsReader.cs | 2 +- .../ExpressionValueSource.cs | 4 ++-- .../JS/JavascriptCompiler.cs | 4 ++-- .../ScoreValueSource.cs | 2 +- .../SortedSetDocValuesFacetCounts.cs | 2 +- .../Taxonomy/SearcherTaxonomyManager.cs | 2 +- .../Taxonomy/WriterCache/CollisionMap.cs | 2 +- .../BlockGroupingCollector.cs | 10 ++++----- src/Lucene.Net.Grouping/GroupingSearch.cs | 4 ++-- .../PostingsHighlight/PostingsHighlighter.cs | 4 ++-- src/Lucene.Net.Join/ToChildBlockJoinQuery.cs | 4 ++-- src/Lucene.Net.Join/ToParentBlockJoinQuery.cs | 12 +++++----- src/Lucene.Net.Misc/Document/LazyDocument.cs | 2 +- .../Index/Sorter/BlockJoinComparatorSource.cs | 4 ++-- .../EarlyTerminatingSortingCollector.cs | 2 +- .../Index/Sorter/SortingMergePolicy.cs | 2 +- .../Core/Processors/QueryNodeProcessorImpl.cs | 2 +- .../Http/ReplicationService.cs | 8 +++---- .../IndexAndTaxonomyReplicationHandler.cs | 2 +- .../IndexInputInputStream.cs | 6 ++--- .../IndexReplicationHandler.cs | 4 ++-- src/Lucene.Net.Replicator/LocalReplicator.cs | 4 ++-- .../ReplicationClient.cs | 2 +- .../DisjointSpatialFilter.cs | 2 +- .../AbstractVisitingPrefixTreeFilter.cs | 2 +- src/Lucene.Net.Spatial/Prefix/Tree/Cell.cs | 2 +- .../Analyzing/AnalyzingInfixSuggester.cs | 10 ++++----- .../Suggest/Analyzing/FreeTextSuggester.cs | 6 ++--- .../Suggest/Fst/ExternalRefSorter.cs | 2 +- .../Suggest/InMemorySorter.cs | 2 +- .../Analysis/MockGraphTokenFilter.cs | 2 +- .../Analysis/ValidatingTokenFilter.cs | 8 +++---- .../Asserting/AssertingDocValuesFormat.cs | 6 ++--- .../MockRandom/MockRandomPostingsFormat.cs | 2 +- .../Index/BaseStoredFieldsFormatTestCase.cs | 6 ++--- .../Index/BaseTermVectorsFormatTestCase.cs | 4 +--- .../Search/AssertingIndexSearcher.cs | 4 ++-- .../Util/LuceneTestCase.cs | 2 +- src/Lucene.Net.TestFramework/Util/TestUtil.cs | 4 ++-- .../AssertingSubDocsAtOnceCollector.cs | 2 +- .../SlowRAMDirectory.cs | 2 +- .../Index/TestIndexReaderClose.cs | 4 ++-- src/Lucene.Net.Tests/Index/TestIndexWriter.cs | 6 ++--- .../Index/TestUniqueTermCount.cs | 4 ++-- src/Lucene.Net/Analysis/NumericTokenStream.cs | 4 ++-- src/Lucene.Net/Analysis/Tokenizer.cs | 4 ++-- src/Lucene.Net/Codecs/BlockTreeTermsReader.cs | 6 ++--- .../CompressingStoredFieldsIndexWriter.cs | 2 +- .../CompressingTermVectorsReader.cs | 12 +++++----- .../Lucene3x/Lucene3xTermVectorsReader.cs | 2 +- .../Codecs/Lucene3x/TermInfosReader.cs | 2 +- .../Lucene40/Lucene40DocValuesReader.cs | 2 +- .../Lucene40/Lucene40TermVectorsReader.cs | 2 +- .../Codecs/Lucene41/Lucene41PostingsReader.cs | 2 +- .../PerField/PerFieldDocValuesFormat.cs | 2 +- .../Codecs/PerField/PerFieldPostingsFormat.cs | 4 ++-- src/Lucene.Net/Document/FieldType.cs | 2 +- .../Index/BinaryDocValuesFieldUpdates.cs | 4 ++-- src/Lucene.Net/Index/DocTermOrds.cs | 4 ++-- .../Index/DocumentsWriterDeleteQueue.cs | 2 +- .../Index/DocumentsWriterPerThreadPool.cs | 2 +- src/Lucene.Net/Index/IndexReader.cs | 2 +- src/Lucene.Net/Index/IndexWriter.cs | 18 +++++++-------- src/Lucene.Net/Index/MergePolicy.cs | 2 +- src/Lucene.Net/Index/MultiTerms.cs | 2 +- src/Lucene.Net/Index/MultiTermsEnum.cs | 2 +- .../Index/NumericDocValuesFieldUpdates.cs | 4 ++-- .../Index/PersistentSnapshotDeletionPolicy.cs | 2 +- src/Lucene.Net/Index/SegmentInfo.cs | 6 ++--- src/Lucene.Net/Index/SegmentInfos.cs | 8 +++---- src/Lucene.Net/Index/SegmentMerger.cs | 2 +- .../Index/SnapshotDeletionPolicy.cs | 6 ++--- src/Lucene.Net/Index/TermsEnum.cs | 16 +++++++------- src/Lucene.Net/Search/CachingCollector.cs | 2 +- src/Lucene.Net/Search/FieldCacheImpl.cs | 18 +++++++-------- src/Lucene.Net/Search/MultiPhraseQuery.cs | 4 ++-- src/Lucene.Net/Search/PhraseQuery.cs | 2 +- src/Lucene.Net/Search/ReferenceManager.cs | 2 +- .../Search/SearcherLifetimeManager.cs | 2 +- src/Lucene.Net/Search/SearcherManager.cs | 2 +- src/Lucene.Net/Search/SortField.cs | 6 ++--- src/Lucene.Net/Search/Spans/SpanTermQuery.cs | 2 +- src/Lucene.Net/Store/ByteBufferIndexInput.cs | 2 +- src/Lucene.Net/Store/CheckSumIndexInput.cs | 2 +- src/Lucene.Net/Store/CompoundFileWriter.cs | 2 +- src/Lucene.Net/Store/FSLockFactory.cs | 2 +- src/Lucene.Net/Store/LockVerifyServer.cs | 4 ++-- src/Lucene.Net/Store/VerifyingLockFactory.cs | 2 +- .../IllegalStateException.cs | 22 +++++++++++++++++++ .../Automaton/DaciukMihovAutomatonBuilder.cs | 2 +- src/Lucene.Net/Util/BytesRef.cs | 14 ++++++------ src/Lucene.Net/Util/CharsRef.cs | 14 ++++++------ src/Lucene.Net/Util/Fst/FST.cs | 12 +++++----- src/Lucene.Net/Util/IntsRef.cs | 14 ++++++------ src/Lucene.Net/Util/LongsRef.cs | 14 ++++++------ .../Packed/AbstractAppendingLongBuffer.cs | 2 +- .../Util/Packed/AbstractBlockPackedWriter.cs | 4 ++-- .../Packed/DirectPacked64SingleBlockReader.cs | 2 +- .../Util/Packed/DirectPackedReader.cs | 2 +- .../Util/Packed/EliasFanoDecoder.cs | 4 ++-- .../Util/Packed/EliasFanoEncoder.cs | 2 +- src/Lucene.Net/Util/Packed/PackedInts.cs | 2 +- src/Lucene.Net/Util/PagedBytes.cs | 8 +++---- src/Lucene.Net/Util/RefCount.cs | 2 +- 115 files changed, 261 insertions(+), 241 deletions(-) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs index 02149f4ca9..3762720058 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs @@ -673,7 +673,7 @@ private FST 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]); } } diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs index ba8c14e444..d76ee694d3 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs @@ -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) { @@ -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) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Sinks/TeeSinkTokenFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Sinks/TeeSinkTokenFilter.cs index 89ad4e6e22..678df888cb 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Sinks/TeeSinkTokenFilter.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Sinks/TeeSinkTokenFilter.cs @@ -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); } diff --git a/src/Lucene.Net.Benchmark/ByTask/Benchmark.cs b/src/Lucene.Net.Benchmark/ByTask/Benchmark.cs index 55c2297249..dc3f504656 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Benchmark.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Benchmark.cs @@ -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(); diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs index eec7519d46..0e9810279a 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs @@ -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; } diff --git a/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs b/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs index a20d344f30..72fc61d9c5 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs @@ -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++) { diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/CommitTaxonomyIndexTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/CommitTaxonomyIndexTask.cs index 4b8cc2cc5d..3273eb7279 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Tasks/CommitTaxonomyIndexTask.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/CommitTaxonomyIndexTask.cs @@ -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; diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/ForceMergeTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/ForceMergeTask.cs index 61c49d173a..68f6b90bad 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Tasks/ForceMergeTask.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/ForceMergeTask.cs @@ -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); diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchWithSortTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchWithSortTask.cs index a24bfa76ff..4f7c1746ca 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchWithSortTask.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchWithSortTask.cs @@ -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; } diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/UpdateDocTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/UpdateDocTask.cs index 68cab7f7ea..6bf50ec69d 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Tasks/UpdateDocTask.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/UpdateDocTask.cs @@ -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); diff --git a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs index f54f385157..fdbdc08955 100644 --- a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs +++ b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs @@ -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); @@ -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); diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs index 7cab3b9d1e..2d2e610bbd 100644 --- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs +++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs @@ -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) { diff --git a/src/Lucene.Net.Expressions/ExpressionValueSource.cs b/src/Lucene.Net.Expressions/ExpressionValueSource.cs index eb805ad51c..f96e911c40 100644 --- a/src/Lucene.Net.Expressions/ExpressionValueSource.cs +++ b/src/Lucene.Net.Expressions/ExpressionValueSource.cs @@ -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."); } } @@ -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; diff --git a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs index 196102c3e5..d2f444350c 100644 --- a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs +++ b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs @@ -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); } } @@ -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 + ")."); } } diff --git a/src/Lucene.Net.Expressions/ScoreValueSource.cs b/src/Lucene.Net.Expressions/ScoreValueSource.cs index a4fdca32de..6a67e1433c 100644 --- a/src/Lucene.Net.Expressions/ScoreValueSource.cs +++ b/src/Lucene.Net.Expressions/ScoreValueSource.cs @@ -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); } diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index 47753c51f0..77ca2ef531 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -177,7 +177,7 @@ private void Count(IList 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); diff --git a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs index 8a5f82d664..39781da53c 100644 --- a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs @@ -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); diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index d4cf6184d7..d2e723bf5d 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -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; diff --git a/src/Lucene.Net.Grouping/BlockGroupingCollector.cs b/src/Lucene.Net.Grouping/BlockGroupingCollector.cs index d51ec89818..097e52517c 100644 --- a/src/Lucene.Net.Grouping/BlockGroupingCollector.cs +++ b/src/Lucene.Net.Grouping/BlockGroupingCollector.cs @@ -100,18 +100,18 @@ 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() @@ -119,11 +119,11 @@ public override long GetCost() return 1; } - public override Weight Weight => throw new InvalidOperationException(); + public override Weight Weight => throw IllegalStateException.Create(); public override ICollection GetChildren() { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } } diff --git a/src/Lucene.Net.Grouping/GroupingSearch.cs b/src/Lucene.Net.Grouping/GroupingSearch.cs index a0c7d15bb2..ccf977efa0 100644 --- a/src/Lucene.Net.Grouping/GroupingSearch.cs +++ b/src/Lucene.Net.Grouping/GroupingSearch.cs @@ -156,7 +156,7 @@ public virtual ITopGroups 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... } } @@ -183,7 +183,7 @@ public virtual ITopGroups Search(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... } } diff --git a/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs b/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs index 3e945063db..f5654dab51 100644 --- a/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs +++ b/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs @@ -520,7 +520,7 @@ private IDictionary 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 @@ -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 pq = new JCG.PriorityQueue(); float[] weights = new float[terms.Length]; diff --git a/src/Lucene.Net.Join/ToChildBlockJoinQuery.cs b/src/Lucene.Net.Join/ToChildBlockJoinQuery.cs index 31f3538b56..55adab2f73 100644 --- a/src/Lucene.Net.Join/ToChildBlockJoinQuery.cs +++ b/src/Lucene.Net.Join/ToChildBlockJoinQuery.cs @@ -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); @@ -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); } } diff --git a/src/Lucene.Net.Join/ToParentBlockJoinQuery.cs b/src/Lucene.Net.Join/ToParentBlockJoinQuery.cs index 2517f90e11..caf4533f35 100644 --- a/src/Lucene.Net.Join/ToParentBlockJoinQuery.cs +++ b/src/Lucene.Net.Join/ToParentBlockJoinQuery.cs @@ -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); @@ -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) @@ -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); @@ -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; @@ -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) @@ -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(); diff --git a/src/Lucene.Net.Misc/Document/LazyDocument.cs b/src/Lucene.Net.Misc/Document/LazyDocument.cs index a220c8edd4..f64d0fdae6 100644 --- a/src/Lucene.Net.Misc/Document/LazyDocument.cs +++ b/src/Lucene.Net.Misc/Document/LazyDocument.cs @@ -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; diff --git a/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs b/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs index bd23dd8f14..57b3c0001a 100644 --- a/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs +++ b/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs @@ -174,11 +174,11 @@ public override FieldComparer SetNextReader(AtomicReaderContext context) DocIdSet parents = outerInstance.parentsFilter.GetDocIdSet(context, null); if (parents == null) { - throw new InvalidOperationException("AtomicReader " + context.AtomicReader + " contains no parents!"); + throw IllegalStateException.Create("AtomicReader " + context.AtomicReader + " contains no parents!"); } if (!(parents is FixedBitSet)) { - throw new InvalidOperationException("parentFilter must return FixedBitSet; got " + parents); + throw IllegalStateException.Create("parentFilter must return FixedBitSet; got " + parents); } parentBits = (FixedBitSet)parents; for (int i = 0; i < parentComparers.Length; i++) diff --git a/src/Lucene.Net.Misc/Index/Sorter/EarlyTerminatingSortingCollector.cs b/src/Lucene.Net.Misc/Index/Sorter/EarlyTerminatingSortingCollector.cs index 5eee50d7e4..ffaf538cdd 100644 --- a/src/Lucene.Net.Misc/Index/Sorter/EarlyTerminatingSortingCollector.cs +++ b/src/Lucene.Net.Misc/Index/Sorter/EarlyTerminatingSortingCollector.cs @@ -91,7 +91,7 @@ public EarlyTerminatingSortingCollector(ICollector @in, Sort sort, int numDocsTo { if (numDocsToCollect <= 0) { - throw new InvalidOperationException("numDocsToCollect must always be > 0, got " + m_segmentTotalCollect); + throw IllegalStateException.Create("numDocsToCollect must always be > 0, got " + m_segmentTotalCollect); } this.m_in = @in; this.m_sort = sort; diff --git a/src/Lucene.Net.Misc/Index/Sorter/SortingMergePolicy.cs b/src/Lucene.Net.Misc/Index/Sorter/SortingMergePolicy.cs index 65a40d0726..401cdca7d5 100644 --- a/src/Lucene.Net.Misc/Index/Sorter/SortingMergePolicy.cs +++ b/src/Lucene.Net.Misc/Index/Sorter/SortingMergePolicy.cs @@ -128,7 +128,7 @@ public override MergePolicy.DocMap GetDocMap(MergeState mergeState) { if (unsortedReaders == null) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } if (docMap == null) { diff --git a/src/Lucene.Net.QueryParser/Flexible/Core/Processors/QueryNodeProcessorImpl.cs b/src/Lucene.Net.QueryParser/Flexible/Core/Processors/QueryNodeProcessorImpl.cs index c7d88b7227..c7483f04ec 100644 --- a/src/Lucene.Net.QueryParser/Flexible/Core/Processors/QueryNodeProcessorImpl.cs +++ b/src/Lucene.Net.QueryParser/Flexible/Core/Processors/QueryNodeProcessorImpl.cs @@ -120,7 +120,7 @@ protected virtual void ProcessChildren(IQueryNode queryTree) if (child2 == null) { // LUCENENET: Changed from NullPointerException to InvalidOperationException (which isn't caught anywhere outside of tests) - throw new InvalidOperationException($"{this.GetType().Name}.PostProcessNode() must not return 'null'."); + throw IllegalStateException.Create($"{this.GetType().Name}.PostProcessNode() must not return 'null'."); } newChildren.Add(child2); diff --git a/src/Lucene.Net.Replicator/Http/ReplicationService.cs b/src/Lucene.Net.Replicator/Http/ReplicationService.cs index 90e20cdafe..8187362bc8 100644 --- a/src/Lucene.Net.Replicator/Http/ReplicationService.cs +++ b/src/Lucene.Net.Replicator/Http/ReplicationService.cs @@ -120,7 +120,7 @@ private static string ExtractRequestParam(IReplicationRequest request, string pa string param = request.QueryParam(paramName); if (param == null) { - throw new InvalidOperationException("Missing mandatory parameter: " + paramName); + throw IllegalStateException.Create("Missing mandatory parameter: " + paramName); } return param; } @@ -136,17 +136,17 @@ public virtual void Perform(IReplicationRequest request, IReplicationResponse re string[] pathElements = GetPathElements(request); if (pathElements.Length != 2) { - throw new InvalidOperationException("invalid path, must contain shard ID and action, e.g. */s1/update"); + throw IllegalStateException.Create("invalid path, must contain shard ID and action, e.g. */s1/update"); } if (!Enum.TryParse(pathElements[ACTION_IDX], true, out ReplicationAction action)) { - throw new InvalidOperationException("Unsupported action provided: " + pathElements[ACTION_IDX]); + throw IllegalStateException.Create("Unsupported action provided: " + pathElements[ACTION_IDX]); } if (!replicators.TryGetValue(pathElements[SHARD_IDX], out IReplicator replicator)) { - throw new InvalidOperationException("unrecognized shard ID " + pathElements[SHARD_IDX]); + throw IllegalStateException.Create("unrecognized shard ID " + pathElements[SHARD_IDX]); } // SOLR-8933 Don't close this stream. diff --git a/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs b/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs index a65e7c9b4c..13a63e8871 100644 --- a/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs +++ b/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs @@ -73,7 +73,7 @@ public IndexAndTaxonomyReplicationHandler(Directory indexDirectory, Directory ta bool taxonomyExists = DirectoryReader.IndexExists(taxonomyDirectory); if (indexExists != taxonomyExists) - throw new InvalidOperationException(string.Format("search and taxonomy indexes must either both exist or not: index={0} taxo={1}", indexExists, taxonomyExists)); + throw IllegalStateException.Create(string.Format("search and taxonomy indexes must either both exist or not: index={0} taxo={1}", indexExists, taxonomyExists)); if (indexExists) { diff --git a/src/Lucene.Net.Replicator/IndexInputInputStream.cs b/src/Lucene.Net.Replicator/IndexInputInputStream.cs index 6a4a944c66..41f31b5bb8 100644 --- a/src/Lucene.Net.Replicator/IndexInputInputStream.cs +++ b/src/Lucene.Net.Replicator/IndexInputInputStream.cs @@ -38,7 +38,7 @@ public IndexInputStream(IndexInput input) public override void Flush() { - throw new InvalidOperationException("Cannot flush a readonly stream."); + throw IllegalStateException.Create("Cannot flush a readonly stream."); // LUCENENET TODO: Change to NotSupportedException ? } public override long Seek(long offset, SeekOrigin origin) @@ -60,7 +60,7 @@ public override long Seek(long offset, SeekOrigin origin) public override void SetLength(long value) { - throw new InvalidOperationException("Cannot change length of a readonly stream."); + throw IllegalStateException.Create("Cannot change length of a readonly stream."); // LUCENENET TODO: Change to NotSupportedException ? } public override int Read(byte[] buffer, int offset, int count) @@ -73,7 +73,7 @@ public override int Read(byte[] buffer, int offset, int count) public override void Write(byte[] buffer, int offset, int count) { - throw new InvalidCastException("Cannot write to a readonly stream."); + throw new InvalidCastException("Cannot write to a readonly stream."); // LUCENENET TODO: Change to NotSupportedException ? } public override bool CanRead => true; diff --git a/src/Lucene.Net.Replicator/IndexReplicationHandler.cs b/src/Lucene.Net.Replicator/IndexReplicationHandler.cs index f9b8438580..ba2f4054d6 100644 --- a/src/Lucene.Net.Replicator/IndexReplicationHandler.cs +++ b/src/Lucene.Net.Replicator/IndexReplicationHandler.cs @@ -112,7 +112,7 @@ public static string GetSegmentsFile(IList files, bool allowEmpty) { if (allowEmpty) return null; - throw new InvalidOperationException("empty list of files not allowed"); + throw IllegalStateException.Create("empty list of files not allowed"); } string segmentsFile = files[files.Count - 1]; @@ -120,7 +120,7 @@ public static string GetSegmentsFile(IList files, bool allowEmpty) files.RemoveAt(files.Count - 1); if (!segmentsFile.StartsWith(IndexFileNames.SEGMENTS, StringComparison.Ordinal) || segmentsFile.Equals(IndexFileNames.SEGMENTS_GEN, StringComparison.Ordinal)) { - throw new InvalidOperationException( + throw IllegalStateException.Create( string.Format("last file to copy+sync must be segments_N but got {0}; check your Revision implementation!", segmentsFile)); } return segmentsFile; diff --git a/src/Lucene.Net.Replicator/LocalReplicator.cs b/src/Lucene.Net.Replicator/LocalReplicator.cs index 82e95ab0b5..cdf77a952a 100644 --- a/src/Lucene.Net.Replicator/LocalReplicator.cs +++ b/src/Lucene.Net.Replicator/LocalReplicator.cs @@ -59,7 +59,7 @@ public virtual void DecRef() { if (refCount <= 0) { - throw new InvalidOperationException("this revision is already released"); + throw IllegalStateException.Create("this revision is already released"); } var rc = refCount.DecrementAndGet(); @@ -82,7 +82,7 @@ public virtual void DecRef() } else if (rc < 0) { - throw new InvalidOperationException(string.Format("too many decRef calls: refCount is {0} after decrement", rc)); + throw IllegalStateException.Create(string.Format("too many decRef calls: refCount is {0} after decrement", rc)); } } diff --git a/src/Lucene.Net.Replicator/ReplicationClient.cs b/src/Lucene.Net.Replicator/ReplicationClient.cs index c6703f79ec..913df08837 100644 --- a/src/Lucene.Net.Replicator/ReplicationClient.cs +++ b/src/Lucene.Net.Replicator/ReplicationClient.cs @@ -411,7 +411,7 @@ public virtual void StartUpdateThread(long intervalMillis, string threadName) { EnsureOpen(); if (updateThread != null && updateThread.IsAlive) - throw new InvalidOperationException("cannot start an update thread when one is running, must first call 'stopUpdateThread()'"); + throw IllegalStateException.Create("cannot start an update thread when one is running, must first call 'stopUpdateThread()'"); threadName = threadName == null ? INFO_STREAM_COMPONENT : "ReplicationThread-" + threadName; updateThread = new ReplicationThread(intervalMillis, threadName, DoUpdate, HandleUpdateException, updateLock); diff --git a/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs b/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs index 5de32552b1..243bfb07d5 100644 --- a/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs +++ b/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs @@ -107,7 +107,7 @@ public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDo int maxDoc = context.AtomicReader.MaxDoc; if (docsWithField.Length != maxDoc) { - throw new InvalidOperationException("Bits length should be maxDoc (" + maxDoc + ") but wasn't: " + docsWithField); + throw IllegalStateException.Create("Bits length should be maxDoc (" + maxDoc + ") but wasn't: " + docsWithField); } if (docsWithField is Bits.MatchNoBits) diff --git a/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs index ac98287fdb..0279687679 100644 --- a/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs +++ b/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs @@ -257,7 +257,7 @@ private void AddIntersectingChildren() Cell cell = curVNode.cell; if (cell.Level >= m_outerInstance.m_detailLevel) { - throw new InvalidOperationException("Spatial logic error"); + throw IllegalStateException.Create("Spatial logic error"); } //Check for adjacent leaf (happens for indexed non-point shapes) if (m_hasIndexedLeaves && cell.Level != 0) diff --git a/src/Lucene.Net.Spatial/Prefix/Tree/Cell.cs b/src/Lucene.Net.Spatial/Prefix/Tree/Cell.cs index 3acf138aaa..068542e92d 100644 --- a/src/Lucene.Net.Spatial/Prefix/Tree/Cell.cs +++ b/src/Lucene.Net.Spatial/Prefix/Tree/Cell.cs @@ -163,7 +163,7 @@ public virtual byte[] GetTokenBytes() { if (b_off != 0 || b_len != bytes.Length) { - throw new InvalidOperationException("Not supported if byte[] needs to be recreated."); + throw IllegalStateException.Create("Not supported if byte[] needs to be recreated."); } } else diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs index 0724734377..6bb4748e29 100644 --- a/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs +++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs @@ -276,12 +276,12 @@ public override void Build(IInputEnumerator enumerator) } } - //LUCENENET specific -Support for LUCENE - 5889. + // LUCENENET specific -Support for LUCENE-5889. public void Commit() { if (writer == null) { - throw new InvalidOperationException("Cannot commit on an closed writer. Add documents first"); + throw IllegalStateException.Create("Cannot commit on an closed writer. Add documents first"); } writer.Commit(); } @@ -406,9 +406,9 @@ private Document BuildDocument(BytesRef text, IEnumerable contexts, lo /// public virtual void Refresh() { - if (m_searcherMgr == null) + if (m_searcherMgr == null) // LUCENENET specific -Support for LUCENE-5889. { - throw new InvalidOperationException("suggester was not built"); + throw IllegalStateException.Create("suggester was not built"); } m_searcherMgr.MaybeRefreshBlocking(); } @@ -465,7 +465,7 @@ public virtual IList DoLookup(string key, IEnumerable co if (m_searcherMgr == null) { - throw new InvalidOperationException("suggester was not built"); + throw IllegalStateException.Create("suggester was not built"); } Occur occur; diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs index 36b0a90f5b..ab42e988d1 100644 --- a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs +++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs @@ -438,7 +438,7 @@ public virtual void Build(IInputEnumerator enumerator, double ramBufferSizeMB) } catch (Exception e) { - throw new InvalidOperationException("failed to remove " + tempIndexPath, e); + throw IllegalStateException.Create("failed to remove " + tempIndexPath, e); } } } @@ -462,12 +462,12 @@ public override bool Load(DataInput input) var separatorOrig = (sbyte)input.ReadByte(); if (separatorOrig != separator) { - throw new InvalidOperationException("separator=" + separator + " is incorrect: original model was built with separator=" + separatorOrig); + throw IllegalStateException.Create("separator=" + separator + " is incorrect: original model was built with separator=" + separatorOrig); } int gramsOrig = input.ReadVInt32(); if (gramsOrig != grams) { - throw new InvalidOperationException("grams=" + grams + " is incorrect: original model was built with grams=" + gramsOrig); + throw IllegalStateException.Create("grams=" + grams + " is incorrect: original model was built with grams=" + gramsOrig); } totTokens = input.ReadVInt64(); diff --git a/src/Lucene.Net.Suggest/Suggest/Fst/ExternalRefSorter.cs b/src/Lucene.Net.Suggest/Suggest/Fst/ExternalRefSorter.cs index 95fa2f023a..40d6efb8fc 100644 --- a/src/Lucene.Net.Suggest/Suggest/Fst/ExternalRefSorter.cs +++ b/src/Lucene.Net.Suggest/Suggest/Fst/ExternalRefSorter.cs @@ -47,7 +47,7 @@ public virtual void Add(BytesRef utf8) { if (writer == null) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } writer.Write(utf8); } diff --git a/src/Lucene.Net.Suggest/Suggest/InMemorySorter.cs b/src/Lucene.Net.Suggest/Suggest/InMemorySorter.cs index ee4e2385ed..8cf4a0ff08 100644 --- a/src/Lucene.Net.Suggest/Suggest/InMemorySorter.cs +++ b/src/Lucene.Net.Suggest/Suggest/InMemorySorter.cs @@ -46,7 +46,7 @@ public void Add(BytesRef utf8) { if (closed) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } buffer.Append(utf8); } diff --git a/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs b/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs index 2ff198fa51..c248a72a5b 100644 --- a/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs +++ b/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs @@ -131,7 +131,7 @@ public override bool IncrementToken() } if (random == null) { - throw AssertionError.Create("IncrementToken() called in wrong state!"); + throw IllegalStateException.Create("IncrementToken() called in wrong state!"); } return NextToken(); } diff --git a/src/Lucene.Net.TestFramework/Analysis/ValidatingTokenFilter.cs b/src/Lucene.Net.TestFramework/Analysis/ValidatingTokenFilter.cs index 699cdf10d3..f7ff468a30 100644 --- a/src/Lucene.Net.TestFramework/Analysis/ValidatingTokenFilter.cs +++ b/src/Lucene.Net.TestFramework/Analysis/ValidatingTokenFilter.cs @@ -97,7 +97,7 @@ public override bool IncrementToken() pos += posIncAtt.PositionIncrement; if (pos == -1) { - throw new InvalidOperationException("first posInc must be > 0"); + throw IllegalStateException.Create("first posInc must be > 0"); } } @@ -110,7 +110,7 @@ public override bool IncrementToken() if (offsetsAreCorrect && offsetAtt.StartOffset < lastStartOffset) { - throw new InvalidOperationException(name + ": offsets must not go backwards startOffset=" + startOffset + " is < lastStartOffset=" + lastStartOffset); + throw IllegalStateException.Create(name + ": offsets must not go backwards startOffset=" + startOffset + " is < lastStartOffset=" + lastStartOffset); } lastStartOffset = offsetAtt.StartOffset; } @@ -132,7 +132,7 @@ public override bool IncrementToken() //System.out.println(" + vs " + pos + " -> " + startOffset); if (oldStartOffset != startOffset) { - throw new InvalidOperationException(name + ": inconsistent startOffset at pos=" + pos + ": " + oldStartOffset + " vs " + startOffset + "; token=" + termAtt); + throw IllegalStateException.Create(name + ": inconsistent startOffset at pos=" + pos + ": " + oldStartOffset + " vs " + startOffset + "; token=" + termAtt); } } @@ -151,7 +151,7 @@ public override bool IncrementToken() //System.out.println(" + ve " + endPos + " -> " + endOffset); if (oldEndOffset != endOffset) { - throw new InvalidOperationException(name + ": inconsistent endOffset at pos=" + endPos + ": " + oldEndOffset + " vs " + endOffset + "; token=" + termAtt); + throw IllegalStateException.Create(name + ": inconsistent endOffset at pos=" + endPos + ": " + oldEndOffset + " vs " + endOffset + "; token=" + termAtt); } } } diff --git a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs index 791ba92160..c27edc66d4 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs @@ -217,17 +217,17 @@ protected override void Dispose(bool disposing) public override void AddBinaryField(FieldInfo field, IEnumerable values) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } public override void AddSortedField(FieldInfo field, IEnumerable values, IEnumerable docToOrd) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } public override void AddSortedSetField(FieldInfo field, IEnumerable values, IEnumerable docToOrdCount, IEnumerable ords) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } } diff --git a/src/Lucene.Net.TestFramework/Codecs/MockRandom/MockRandomPostingsFormat.cs b/src/Lucene.Net.TestFramework/Codecs/MockRandom/MockRandomPostingsFormat.cs index 6ca444563c..7c9628cdc0 100644 --- a/src/Lucene.Net.TestFramework/Codecs/MockRandom/MockRandomPostingsFormat.cs +++ b/src/Lucene.Net.TestFramework/Codecs/MockRandom/MockRandomPostingsFormat.cs @@ -50,7 +50,7 @@ public RandomAnonymousClassHelper() public override int Next(int maxValue) { - throw new InvalidOperationException("Please use MockRandomPostingsFormat(Random)"); + throw IllegalStateException.Create("Please use MockRandomPostingsFormat(Random)"); } } diff --git a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs index a1d6788aed..7c167bf8b9 100644 --- a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs +++ b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs @@ -554,16 +554,16 @@ public override void Run() if (topDocs.TotalHits != 1) { Console.WriteLine(query); - throw new InvalidOperationException("Expected 1 hit, got " + topDocs.TotalHits); + throw IllegalStateException.Create("Expected 1 hit, got " + topDocs.TotalHits); } Document sdoc = rd.Document(topDocs.ScoreDocs[0].Doc); if (sdoc == null || sdoc.Get("fld") == null) { - throw new InvalidOperationException("Could not find document " + q); + throw IllegalStateException.Create("Could not find document " + q); } if (!Convert.ToString(q, CultureInfo.InvariantCulture).Equals(sdoc.Get("fld"), StringComparison.Ordinal)) { - throw new InvalidOperationException("Expected " + q + ", but got " + sdoc.Get("fld")); + throw IllegalStateException.Create("Expected " + q + ", but got " + sdoc.Get("fld")); } } catch (Exception e) when (e.IsException()) diff --git a/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs index 0709aac539..ca544a2af3 100644 --- a/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs +++ b/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs @@ -46,8 +46,6 @@ namespace Lucene.Net.Index * limitations under the License. */ - using AssertionError = Lucene.Net.Diagnostics.AssertionException; // LUCENENET TODO: Remove this after converting to the .IsAssertionError() extension method in catch blocks - /// /// Base class aiming at testing . /// To test a new format, all you need is to register a new which @@ -126,7 +124,7 @@ public OptionsWrapper(Options opt) break; default: - throw new InvalidOperationException("Invalid Options enum type"); + throw new ArgumentOutOfRangeException(nameof(opt), "Invalid Options enum type"); } } diff --git a/src/Lucene.Net.TestFramework/Search/AssertingIndexSearcher.cs b/src/Lucene.Net.TestFramework/Search/AssertingIndexSearcher.cs index 00d2a7bf86..907a59b3a6 100644 --- a/src/Lucene.Net.TestFramework/Search/AssertingIndexSearcher.cs +++ b/src/Lucene.Net.TestFramework/Search/AssertingIndexSearcher.cs @@ -73,12 +73,12 @@ public AssertingWeightAnonymousClass(Random random, Weight w) public override void Normalize(float norm, float topLevelBoost) { - throw new InvalidOperationException("Weight already normalized."); + throw IllegalStateException.Create("Weight already normalized."); } public override float GetValueForNormalization() { - throw new InvalidOperationException("Weight already normalized."); + throw IllegalStateException.Create("Weight already normalized."); } } diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index 815df26775..1a3280193c 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -2144,7 +2144,7 @@ private static Directory NewDirectoryImpl(Random random, string clazzName) Type clazz = CommandLineUtil.LoadDirectoryClass(clazzName); if (clazz == null) - throw new InvalidOperationException($"Type '{clazzName}' could not be instantiated."); + throw IllegalStateException.Create($"Type '{clazzName}' could not be instantiated."); // LUCENENET: We don't get an exception in this case, so throwing one for compatibility // If it is a FSDirectory type, try its ctor(File) if (typeof(FSDirectory).IsAssignableFrom(clazz)) { diff --git a/src/Lucene.Net.TestFramework/Util/TestUtil.cs b/src/Lucene.Net.TestFramework/Util/TestUtil.cs index 97c751b1cd..2d880b967d 100644 --- a/src/Lucene.Net.TestFramework/Util/TestUtil.cs +++ b/src/Lucene.Net.TestFramework/Util/TestUtil.cs @@ -737,7 +737,7 @@ public static Document CloneDocument(Document doc1) break; default: - throw new InvalidOperationException("unknown Type: " + dvType); + throw IllegalStateException.Create("unknown Type: " + dvType); } } else if (numType != NumericType.NONE) @@ -761,7 +761,7 @@ public static Document CloneDocument(Document doc1) break; default: - throw new InvalidOperationException("unknown Type: " + numType); + throw IllegalStateException.Create("unknown Type: " + numType); } } else diff --git a/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs b/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs index a8c1e3d29d..d64d1a6796 100644 --- a/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs +++ b/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs @@ -58,7 +58,7 @@ public virtual void Collect(int docID) { if (docID != s.DocID) { - throw new InvalidOperationException("subScorer=" + s + " has docID=" + s.DocID + " != collected docID=" + docID); + throw IllegalStateException.Create("subScorer=" + s + " has docID=" + s.DocID + " != collected docID=" + docID); } } } diff --git a/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs b/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs index d333fb8823..10affacb41 100644 --- a/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs +++ b/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs @@ -241,7 +241,7 @@ public override long GetFilePointer() public override long Length { get => io.Length; - set => throw new InvalidOperationException("Length is readonly"); + set => throw IllegalStateException.Create("Length is readonly"); // LUCENENET specific: We cannot override get without also overriding set, so we throw if it is set } public override long Checksum => io.Checksum; diff --git a/src/Lucene.Net.Tests/Index/TestIndexReaderClose.cs b/src/Lucene.Net.Tests/Index/TestIndexReaderClose.cs index ab6051abc5..d717db4f97 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexReaderClose.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexReaderClose.cs @@ -121,7 +121,7 @@ protected internal override void DoClose() base.DoClose(); if (throwOnClose) { - throw new InvalidOperationException("BOOM!"); + throw IllegalStateException.Create("BOOM!"); } } } @@ -145,7 +145,7 @@ private sealed class FaultyListener : IndexReader.IReaderClosedListener { public void OnClose(IndexReader reader) { - throw new InvalidOperationException("GRRRRRRRRRRRR!"); + throw IllegalStateException.Create("GRRRRRRRRRRRR!"); } } } diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs index 819943e38e..3919b360d0 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs @@ -2301,17 +2301,17 @@ public AnalyzerAnonymousClass(TestIndexWriter outerInstance) protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader reader) { - throw new InvalidOperationException("don't invoke me!"); + throw IllegalStateException.Create("don't invoke me!"); } public override int GetPositionIncrementGap(string fieldName) { - throw new InvalidOperationException("don't invoke me!"); + throw IllegalStateException.Create("don't invoke me!"); } public override int GetOffsetGap(string fieldName) { - throw new InvalidOperationException("don't invoke me!"); + throw IllegalStateException.Create("don't invoke me!"); } } diff --git a/src/Lucene.Net.Tests/Index/TestUniqueTermCount.cs b/src/Lucene.Net.Tests/Index/TestUniqueTermCount.cs index 3c49f21255..0513530d52 100644 --- a/src/Lucene.Net.Tests/Index/TestUniqueTermCount.cs +++ b/src/Lucene.Net.Tests/Index/TestUniqueTermCount.cs @@ -112,12 +112,12 @@ public override long ComputeNorm(FieldInvertState state) public override SimWeight ComputeWeight(float queryBoost, CollectionStatistics collectionStats, params TermStatistics[] termStats) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } public override SimScorer GetSimScorer(SimWeight weight, AtomicReaderContext context) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } } } diff --git a/src/Lucene.Net/Analysis/NumericTokenStream.cs b/src/Lucene.Net/Analysis/NumericTokenStream.cs index 5312337c6f..290e18ab52 100644 --- a/src/Lucene.Net/Analysis/NumericTokenStream.cs +++ b/src/Lucene.Net/Analysis/NumericTokenStream.cs @@ -328,7 +328,7 @@ public override void Reset() { if (valSize == 0) { - throw new InvalidOperationException("call Set???Value() before usage"); + throw IllegalStateException.Create("call Set???Value() before usage"); } numericAtt.Shift = -precisionStep; } @@ -337,7 +337,7 @@ public override bool IncrementToken() { if (valSize == 0) { - throw new InvalidOperationException("call Set???Value() before usage"); + throw IllegalStateException.Create("call Set???Value() before usage"); } // this will only clear all other attributes in this TokenStream diff --git a/src/Lucene.Net/Analysis/Tokenizer.cs b/src/Lucene.Net/Analysis/Tokenizer.cs index ac7cb13ed3..d8f889725b 100644 --- a/src/Lucene.Net/Analysis/Tokenizer.cs +++ b/src/Lucene.Net/Analysis/Tokenizer.cs @@ -105,7 +105,7 @@ public void SetReader(TextReader input) } else if (this.m_input != ILLEGAL_STATE_READER) { - throw new InvalidOperationException("TokenStream contract violation: Close() call missing"); + throw IllegalStateException.Create("TokenStream contract violation: Close() call missing"); } this.inputPending = input; if (Debugging.AssertsEnabled) Debugging.Assert(SetReaderTestPoint()); @@ -130,7 +130,7 @@ private class ReaderAnonymousClass : TextReader { public override int Read(char[] cbuf, int off, int len) { - throw new InvalidOperationException("TokenStream contract violation: Reset()/Dispose() call missing, " + throw IllegalStateException.Create("TokenStream contract violation: Reset()/Dispose() call missing, " + "Reset() called multiple times, or subclass does not call base.Reset(). " + "Please see the documentation of TokenStream class for more information about the correct consuming workflow."); } diff --git a/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs b/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs index d5128c7d98..1a85c4bf84 100644 --- a/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs +++ b/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs @@ -472,7 +472,7 @@ internal virtual void EndBlock(FieldReader.SegmentTermsEnum.Frame frame) } else { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } endBlockCount++; long otherBytes = frame.fpEnd - frame.fp - frame.suffixesReader.Length - frame.statsReader.Length; @@ -1797,7 +1797,7 @@ public override bool SeekExact(BytesRef target) { if (outerInstance.index == null) { - throw new InvalidOperationException("terms index was not loaded"); + throw IllegalStateException.Create("terms index was not loaded"); } if (term.Bytes.Length <= target.Length) @@ -2084,7 +2084,7 @@ public override SeekStatus SeekCeil(BytesRef target) { if (outerInstance.index == null) { - throw new InvalidOperationException("terms index was not loaded"); + throw IllegalStateException.Create("terms index was not loaded"); } if (term.Bytes.Length <= target.Length) diff --git a/src/Lucene.Net/Codecs/Compressing/CompressingStoredFieldsIndexWriter.cs b/src/Lucene.Net/Codecs/Compressing/CompressingStoredFieldsIndexWriter.cs index c57cf33f8f..95022efdf9 100644 --- a/src/Lucene.Net/Codecs/Compressing/CompressingStoredFieldsIndexWriter.cs +++ b/src/Lucene.Net/Codecs/Compressing/CompressingStoredFieldsIndexWriter.cs @@ -214,7 +214,7 @@ internal void Finish(int numDocs, long maxPointer) { if (numDocs != totalDocs) { - throw new InvalidOperationException("Expected " + numDocs + " docs, but got " + totalDocs); + throw IllegalStateException.Create("Expected " + numDocs + " docs, but got " + totalDocs); } if (blockChunks > 0) { diff --git a/src/Lucene.Net/Codecs/Compressing/CompressingTermVectorsReader.cs b/src/Lucene.Net/Codecs/Compressing/CompressingTermVectorsReader.cs index d8886bff6c..fe7561ac93 100644 --- a/src/Lucene.Net/Codecs/Compressing/CompressingTermVectorsReader.cs +++ b/src/Lucene.Net/Codecs/Compressing/CompressingTermVectorsReader.cs @@ -983,11 +983,11 @@ private void CheckDoc() { if (doc == NO_MORE_DOCS) { - throw new InvalidOperationException("DocsEnum exhausted"); + throw IllegalStateException.Create("DocsEnum exhausted"); } else if (doc == -1) { - throw new InvalidOperationException("DocsEnum not started"); + throw IllegalStateException.Create("DocsEnum not started"); } } @@ -997,11 +997,11 @@ private void CheckPosition() CheckDoc(); if (i < 0) { - throw new InvalidOperationException("Position enum not started"); + throw IllegalStateException.Create("Position enum not started"); } else if (i >= termFreq) { - throw new InvalidOperationException("Read past last position"); + throw IllegalStateException.Create("Read past last position"); } } @@ -1009,11 +1009,11 @@ public override int NextPosition() { if (doc != 0) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } else if (i >= termFreq - 1) { - throw new InvalidOperationException("Read past last position"); + throw IllegalStateException.Create("Read past last position"); } ++i; diff --git a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs index d7c8696283..5fb71c447b 100644 --- a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs +++ b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs @@ -767,7 +767,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) { diff --git a/src/Lucene.Net/Codecs/Lucene3x/TermInfosReader.cs b/src/Lucene.Net/Codecs/Lucene3x/TermInfosReader.cs index fc0d201365..f920ca611d 100644 --- a/src/Lucene.Net/Codecs/Lucene3x/TermInfosReader.cs +++ b/src/Lucene.Net/Codecs/Lucene3x/TermInfosReader.cs @@ -384,7 +384,7 @@ private void EnsureIndexIsRead() { if (index == null) { - throw new InvalidOperationException("terms index was not loaded when this reader was created"); + throw IllegalStateException.Create("terms index was not loaded when this reader was created"); } } diff --git a/src/Lucene.Net/Codecs/Lucene40/Lucene40DocValuesReader.cs b/src/Lucene.Net/Codecs/Lucene40/Lucene40DocValuesReader.cs index fd1b3c10d2..55b1a7a741 100644 --- a/src/Lucene.Net/Codecs/Lucene40/Lucene40DocValuesReader.cs +++ b/src/Lucene.Net/Codecs/Lucene40/Lucene40DocValuesReader.cs @@ -888,7 +888,7 @@ public override void LookupOrd(int ord, BytesRef result) public override SortedSetDocValues GetSortedSet(FieldInfo field) { - throw new InvalidOperationException("Lucene 4.0 does not support SortedSet: how did you pull this off?"); + throw IllegalStateException.Create("Lucene 4.0 does not support SortedSet: how did you pull this off?"); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs b/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs index a1c970a0af..897271f7b5 100644 --- a/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs +++ b/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs @@ -732,7 +732,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) { diff --git a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs index 414bd3a6ef..33c4bbb129 100644 --- a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs +++ b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs @@ -94,7 +94,7 @@ public override void Init(IndexInput termsIn) int indexBlockSize = termsIn.ReadVInt32(); if (indexBlockSize != Lucene41PostingsFormat.BLOCK_SIZE) { - throw new InvalidOperationException("index-time BLOCK_SIZE (" + indexBlockSize + ") != read-time BLOCK_SIZE (" + Lucene41PostingsFormat.BLOCK_SIZE + ")"); + throw IllegalStateException.Create("index-time BLOCK_SIZE (" + indexBlockSize + ") != read-time BLOCK_SIZE (" + Lucene41PostingsFormat.BLOCK_SIZE + ")"); } } diff --git a/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs b/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs index ddc3102173..818fe52c60 100644 --- a/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs +++ b/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs @@ -155,7 +155,7 @@ internal virtual DocValuesConsumer GetInstance(FieldInfo field) } if (format == null) { - throw new InvalidOperationException("invalid null DocValuesFormat for field=\"" + field.Name + "\""); + throw IllegalStateException.Create("invalid null DocValuesFormat for field=\"" + field.Name + "\""); } string formatName_ = format.Name; diff --git a/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs b/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs index def4773904..c16ef24ab2 100644 --- a/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs +++ b/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs @@ -113,7 +113,7 @@ public override TermsConsumer AddField(FieldInfo field) PostingsFormat format = outerInstance.GetPostingsFormatForField(field.Name); if (format == null) { - throw new InvalidOperationException("invalid null PostingsFormat for field=\"" + field.Name + "\""); + throw IllegalStateException.Create("invalid null PostingsFormat for field=\"" + field.Name + "\""); } string formatName = format.Name; @@ -192,7 +192,7 @@ internal static string GetFullSegmentSuffix(string fieldName, string outerSegmen // TODO: support embedding; I think it should work but // we need a test confirm to confirm // return outerSegmentSuffix + "_" + segmentSuffix; - throw new InvalidOperationException("cannot embed PerFieldPostingsFormat inside itself (field \"" + fieldName + "\" returned PerFieldPostingsFormat)"); + throw IllegalStateException.Create("cannot embed PerFieldPostingsFormat inside itself (field \"" + fieldName + "\" returned PerFieldPostingsFormat)"); } } diff --git a/src/Lucene.Net/Document/FieldType.cs b/src/Lucene.Net/Document/FieldType.cs index 8cf579ae8c..20e1bb1a59 100644 --- a/src/Lucene.Net/Document/FieldType.cs +++ b/src/Lucene.Net/Document/FieldType.cs @@ -73,7 +73,7 @@ private void CheckIfFrozen() { if (frozen) { - throw new InvalidOperationException("this FieldType is already frozen and cannot be changed"); + throw IllegalStateException.Create("this FieldType is already frozen and cannot be changed"); } } diff --git a/src/Lucene.Net/Index/BinaryDocValuesFieldUpdates.cs b/src/Lucene.Net/Index/BinaryDocValuesFieldUpdates.cs index 0d9f036097..926db4a03f 100644 --- a/src/Lucene.Net/Index/BinaryDocValuesFieldUpdates.cs +++ b/src/Lucene.Net/Index/BinaryDocValuesFieldUpdates.cs @@ -140,7 +140,7 @@ public override void Add(int doc, object value) // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation if (size == int.MaxValue) { - throw new InvalidOperationException("cannot support more than System.Int32.MaxValue doc/value entries"); + throw IllegalStateException.Create("cannot support more than System.Int32.MaxValue doc/value entries"); } BytesRef val = (BytesRef)value; @@ -246,7 +246,7 @@ public override void Merge(DocValuesFieldUpdates other) int newSize = size + otherUpdates.size; if (newSize > int.MaxValue) { - throw new InvalidOperationException("cannot support more than System.Int32.MaxValue doc/value entries; size=" + size + " other.size=" + otherUpdates.size); + throw IllegalStateException.Create("cannot support more than System.Int32.MaxValue doc/value entries; size=" + size + " other.size=" + otherUpdates.size); } docs = docs.Grow(newSize); offsets = offsets.Grow(newSize); diff --git a/src/Lucene.Net/Index/DocTermOrds.cs b/src/Lucene.Net/Index/DocTermOrds.cs index 41110bb831..61b384f7e3 100644 --- a/src/Lucene.Net/Index/DocTermOrds.cs +++ b/src/Lucene.Net/Index/DocTermOrds.cs @@ -331,7 +331,7 @@ protected virtual void Uninvert(AtomicReader reader, IBits liveDocs, BytesRef te FieldInfo info = reader.FieldInfos.FieldInfo(m_field); if (info != null && info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + m_field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + m_field + " was indexed as " + info.DocValuesType); } //System.out.println("DTO uninvert field=" + field + " prefix=" + termPrefix); long startTime = Environment.TickCount; @@ -604,7 +604,7 @@ protected virtual void Uninvert(AtomicReader reader, IBits liveDocs, BytesRef te if ((pos & 0xff000000) != 0) { // we only have 24 bits for the array index - throw new InvalidOperationException("Too many values for UnInvertedField faceting on field " + m_field); + throw IllegalStateException.Create("Too many values for UnInvertedField faceting on field " + m_field); } var arr = bytes[doc]; /* diff --git a/src/Lucene.Net/Index/DocumentsWriterDeleteQueue.cs b/src/Lucene.Net/Index/DocumentsWriterDeleteQueue.cs index 5be829ac7d..e378aea6ed 100644 --- a/src/Lucene.Net/Index/DocumentsWriterDeleteQueue.cs +++ b/src/Lucene.Net/Index/DocumentsWriterDeleteQueue.cs @@ -375,7 +375,7 @@ internal Node(object item) internal virtual void Apply(BufferedUpdates bufferedDeletes, int docIDUpto) { - throw new InvalidOperationException("sentinel item must never be applied"); + throw IllegalStateException.Create("sentinel item must never be applied"); } internal virtual bool CasNext(Node cmp, Node val) diff --git a/src/Lucene.Net/Index/DocumentsWriterPerThreadPool.cs b/src/Lucene.Net/Index/DocumentsWriterPerThreadPool.cs index 3f5e6cc969..10240f8b97 100644 --- a/src/Lucene.Net/Index/DocumentsWriterPerThreadPool.cs +++ b/src/Lucene.Net/Index/DocumentsWriterPerThreadPool.cs @@ -181,7 +181,7 @@ public object Clone() // We should only be cloned before being used: if (numThreadStatesActive != 0) { - throw new InvalidOperationException("clone this object before it is used!"); + throw IllegalStateException.Create("clone this object before it is used!"); } return new DocumentsWriterPerThreadPool(threadStates.Length); } diff --git a/src/Lucene.Net/Index/IndexReader.cs b/src/Lucene.Net/Index/IndexReader.cs index b3695ef8e4..47fc06a11f 100644 --- a/src/Lucene.Net/Index/IndexReader.cs +++ b/src/Lucene.Net/Index/IndexReader.cs @@ -296,7 +296,7 @@ public void DecRef() } else if (rc < 0) { - throw new InvalidOperationException("too many decRef calls: refCount is " + rc + " after decrement"); + throw IllegalStateException.Create("too many decRef calls: refCount is " + rc + " after decrement"); } } diff --git a/src/Lucene.Net/Index/IndexWriter.cs b/src/Lucene.Net/Index/IndexWriter.cs index ae498c6267..df6029c470 100644 --- a/src/Lucene.Net/Index/IndexWriter.cs +++ b/src/Lucene.Net/Index/IndexWriter.cs @@ -1135,7 +1135,7 @@ private void CloseInternal(bool waitForMerges, bool doFlush) { if (pendingCommit != null) { - throw new InvalidOperationException("cannot close: prepareCommit was already called with no corresponding call to commit"); + throw IllegalStateException.Create("cannot close: prepareCommit was already called with no corresponding call to commit"); } if (infoStream.IsEnabled("IW")) @@ -2147,7 +2147,7 @@ public virtual void ForceMerge(int maxNumSegments, bool doWait) { if (hitOOM) { - throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot complete forceMerge"); + throw IllegalStateException.Create("this writer hit an OutOfMemoryError; cannot complete forceMerge"); } if (mergeExceptions.Count > 0) @@ -2278,7 +2278,7 @@ public virtual void ForceMergeDeletes(bool doWait) { if (hitOOM) { - throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot complete forceMergeDeletes"); + throw IllegalStateException.Create("this writer hit an OutOfMemoryError; cannot complete forceMergeDeletes"); } // Check each merge that MergePolicy asked us to @@ -3534,12 +3534,12 @@ private void PrepareCommitInternal() if (hitOOM) { - throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot commit"); + throw IllegalStateException.Create("this writer hit an OutOfMemoryError; cannot commit"); } if (pendingCommit != null) { - throw new InvalidOperationException("prepareCommit was already called with no corresponding call to commit"); + throw IllegalStateException.Create("prepareCommit was already called with no corresponding call to commit"); } DoBeforeFlush(); @@ -3854,7 +3854,7 @@ private bool DoFlush(bool applyAllDeletes) { if (hitOOM) { - throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot flush"); + throw IllegalStateException.Create("this writer hit an OutOfMemoryError; cannot flush"); } DoBeforeFlush(); @@ -4337,7 +4337,7 @@ private bool CommitMerge(MergePolicy.OneMerge merge, MergeState mergeState) if (hitOOM) { - throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot complete merge"); + throw IllegalStateException.Create("this writer hit an OutOfMemoryError; cannot complete merge"); } if (infoStream.IsEnabled("IW")) @@ -4768,7 +4768,7 @@ private void MergeInitImpl(MergePolicy.OneMerge merge) // LUCENENET specific: re if (hitOOM) { - throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot merge"); + throw IllegalStateException.Create("this writer hit an OutOfMemoryError; cannot merge"); } if (merge.info != null) @@ -5438,7 +5438,7 @@ private void StartCommit(SegmentInfos toSync) if (hitOOM) { - throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot commit"); + throw IllegalStateException.Create("this writer hit an OutOfMemoryError; cannot commit"); } try diff --git a/src/Lucene.Net/Index/MergePolicy.cs b/src/Lucene.Net/Index/MergePolicy.cs index 8ee2884a1f..cf6f5ac250 100644 --- a/src/Lucene.Net/Index/MergePolicy.cs +++ b/src/Lucene.Net/Index/MergePolicy.cs @@ -178,7 +178,7 @@ public virtual IList GetMergeReaders() { if (this.readers == null) { - throw new InvalidOperationException("IndexWriter has not initialized readers from the segment infos yet"); + throw IllegalStateException.Create("IndexWriter has not initialized readers from the segment infos yet"); } IList readers = new List(this.readers.Count); foreach (AtomicReader reader in this.readers) diff --git a/src/Lucene.Net/Index/MultiTerms.cs b/src/Lucene.Net/Index/MultiTerms.cs index 5843b865d6..d7167dd69d 100644 --- a/src/Lucene.Net/Index/MultiTerms.cs +++ b/src/Lucene.Net/Index/MultiTerms.cs @@ -72,7 +72,7 @@ public MultiTerms(Terms[] subs, ReaderSlice[] subSlices) IComparer subTermComp = subs[i].Comparer; if (subTermComp != null && !subTermComp.Equals(_termComp)) { - throw new InvalidOperationException("sub-readers have different BytesRef.Comparers; cannot merge"); + throw IllegalStateException.Create("sub-readers have different BytesRef.Comparers; cannot merge"); } } _hasFreqs &= subs[i].HasFreqs; diff --git a/src/Lucene.Net/Index/MultiTermsEnum.cs b/src/Lucene.Net/Index/MultiTermsEnum.cs index e007219d56..73cb678c1f 100644 --- a/src/Lucene.Net/Index/MultiTermsEnum.cs +++ b/src/Lucene.Net/Index/MultiTermsEnum.cs @@ -129,7 +129,7 @@ public TermsEnum Reset(TermsEnumIndex[] termsEnumsIndex) IComparer subTermComp = termsEnumIndex.TermsEnum.Comparer; if (subTermComp != null && !subTermComp.Equals(termComp)) { - throw new InvalidOperationException("sub-readers have different BytesRef.Comparers: " + subTermComp + " vs " + termComp + "; cannot merge"); + throw IllegalStateException.Create("sub-readers have different BytesRef.Comparers: " + subTermComp + " vs " + termComp + "; cannot merge"); } } diff --git a/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs b/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs index d4f47165bf..900b81477d 100644 --- a/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs +++ b/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs @@ -112,7 +112,7 @@ public override void Add(int doc, object value) // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation if (size == int.MaxValue) { - throw new InvalidOperationException("cannot support more than System.Int32.MaxValue doc/value entries"); + throw IllegalStateException.Create("cannot support more than System.Int32.MaxValue doc/value entries"); } long? val = (long?)value; @@ -207,7 +207,7 @@ public override void Merge(DocValuesFieldUpdates other) NumericDocValuesFieldUpdates otherUpdates = (NumericDocValuesFieldUpdates)other; if (size + otherUpdates.size > int.MaxValue) { - throw new InvalidOperationException("cannot support more than System.Int32.MaxValue doc/value entries; size=" + size + " other.size=" + otherUpdates.size); + throw IllegalStateException.Create("cannot support more than System.Int32.MaxValue doc/value entries; size=" + size + " other.size=" + otherUpdates.size); } docs = docs.Grow(size + otherUpdates.size); values = values.Grow(size + otherUpdates.size); diff --git a/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs b/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs index a568901a03..ae0f512d06 100644 --- a/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs +++ b/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs @@ -111,7 +111,7 @@ public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory d if (mode == OpenMode.APPEND && nextWriteGen == 0) { - throw new InvalidOperationException("no snapshots stored in this directory"); + throw IllegalStateException.Create("no snapshots stored in this directory"); } } diff --git a/src/Lucene.Net/Index/SegmentInfo.cs b/src/Lucene.Net/Index/SegmentInfo.cs index 1ed6c8ae88..550cb1c704 100644 --- a/src/Lucene.Net/Index/SegmentInfo.cs +++ b/src/Lucene.Net/Index/SegmentInfo.cs @@ -152,7 +152,7 @@ public int DocCount { if (this.docCount == -1) { - throw new InvalidOperationException("docCount isn't set yet"); + throw IllegalStateException.Create("docCount isn't set yet"); } return docCount; } @@ -160,7 +160,7 @@ public int DocCount { if (this.docCount != -1) { - throw new InvalidOperationException("docCount was already set"); + throw IllegalStateException.Create("docCount was already set"); } this.docCount = value; } @@ -172,7 +172,7 @@ public ISet GetFiles() { if (setFiles == null) { - throw new InvalidOperationException("files were not computed yet"); + throw IllegalStateException.Create("files were not computed yet"); } return setFiles.AsReadOnly(); } diff --git a/src/Lucene.Net/Index/SegmentInfos.cs b/src/Lucene.Net/Index/SegmentInfos.cs index 7532d347db..3bec340331 100644 --- a/src/Lucene.Net/Index/SegmentInfos.cs +++ b/src/Lucene.Net/Index/SegmentInfos.cs @@ -529,7 +529,7 @@ private void Write(Directory directory) int delCount = siPerCommit.DelCount; if (delCount < 0 || delCount > si.DocCount) { - throw new InvalidOperationException("cannot write segment: invalid docCount segment=" + si.Name + " docCount=" + si.DocCount + " delCount=" + delCount); + throw IllegalStateException.Create("cannot write segment: invalid docCount segment=" + si.Name + " docCount=" + si.DocCount + " delCount=" + delCount); } segnOutput.WriteInt32(delCount); segnOutput.WriteInt64(siPerCommit.FieldInfosGen); @@ -659,7 +659,7 @@ public static string Write3xInfo(Directory dir, SegmentInfo si, IOContext contex // so it had better be a 3.x segment or you will get very confusing errors later. if ((si.Codec is Lucene3xCodec) == false) { - throw new InvalidOperationException("cannot write 3x SegmentInfo unless codec is Lucene3x (got: " + si.Codec + ")"); + throw IllegalStateException.Create("cannot write 3x SegmentInfo unless codec is Lucene3x (got: " + si.Codec + ")"); } CodecUtil.WriteHeader(output, Lucene3xSegmentInfoFormat.UPGRADED_SI_CODEC_NAME, Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_CURRENT); @@ -1119,7 +1119,7 @@ internal void PrepareCommit(Directory dir) { if (pendingSegnOutput != null) { - throw new InvalidOperationException("prepareCommit was already called"); + throw IllegalStateException.Create("prepareCommit was already called"); } Write(dir); } @@ -1161,7 +1161,7 @@ internal void FinishCommit(Directory dir) { if (pendingSegnOutput == null) { - throw new InvalidOperationException("prepareCommit was not called"); + throw IllegalStateException.Create("prepareCommit was not called"); } bool success = false; try diff --git a/src/Lucene.Net/Index/SegmentMerger.cs b/src/Lucene.Net/Index/SegmentMerger.cs index 42496c5b22..96a41a4b37 100644 --- a/src/Lucene.Net/Index/SegmentMerger.cs +++ b/src/Lucene.Net/Index/SegmentMerger.cs @@ -89,7 +89,7 @@ internal MergeState Merge() { if (!ShouldMerge) { - throw new InvalidOperationException("Merge would result in 0 document segment"); + throw IllegalStateException.Create("Merge would result in 0 document segment"); } // NOTE: it's important to add calls to // checkAbort.work(...) if you make any changes to this diff --git a/src/Lucene.Net/Index/SnapshotDeletionPolicy.cs b/src/Lucene.Net/Index/SnapshotDeletionPolicy.cs index e070f6d4f7..44c92e9dde 100644 --- a/src/Lucene.Net/Index/SnapshotDeletionPolicy.cs +++ b/src/Lucene.Net/Index/SnapshotDeletionPolicy.cs @@ -122,7 +122,7 @@ protected internal virtual void ReleaseGen(long gen) { if (!initCalled) { - throw new InvalidOperationException("this instance is not being used by IndexWriter; be sure to use the instance returned from writer.Config.IndexDeletionPolicy"); + throw IllegalStateException.Create("this instance is not being used by IndexWriter; be sure to use the instance returned from writer.Config.IndexDeletionPolicy"); } int? refCount = m_refCounts[gen]; if (refCount == null) @@ -186,12 +186,12 @@ public virtual IndexCommit Snapshot() { if (!initCalled) { - throw new InvalidOperationException("this instance is not being used by IndexWriter; be sure to use the instance returned from writer.Config.IndexDeletionPolicy"); + throw IllegalStateException.Create("this instance is not being used by IndexWriter; be sure to use the instance returned from writer.Config.IndexDeletionPolicy"); } if (m_lastCommit == null) { // No commit yet, eg this is a new IndexWriter: - throw new InvalidOperationException("No index commit to snapshot"); + throw IllegalStateException.Create("No index commit to snapshot"); } IncRef(m_lastCommit); diff --git a/src/Lucene.Net/Index/TermsEnum.cs b/src/Lucene.Net/Index/TermsEnum.cs index 25a9a2810f..fdfaea5fad 100644 --- a/src/Lucene.Net/Index/TermsEnum.cs +++ b/src/Lucene.Net/Index/TermsEnum.cs @@ -300,24 +300,24 @@ public override void SeekExact(long ord) { } - public override BytesRef Term => throw new InvalidOperationException("this method should never be called"); + public override BytesRef Term => throw IllegalStateException.Create("this method should never be called"); public override IComparer Comparer => null; - public override int DocFreq => throw new InvalidOperationException("this method should never be called"); + public override int DocFreq => throw IllegalStateException.Create("this method should never be called"); - public override long TotalTermFreq => throw new InvalidOperationException("this method should never be called"); + public override long TotalTermFreq => throw IllegalStateException.Create("this method should never be called"); - public override long Ord => throw new InvalidOperationException("this method should never be called"); + public override long Ord => throw IllegalStateException.Create("this method should never be called"); public override DocsEnum Docs(IBits liveDocs, DocsEnum reuse, DocsFlags flags) { - throw new InvalidOperationException("this method should never be called"); + throw IllegalStateException.Create("this method should never be called"); } public override DocsAndPositionsEnum DocsAndPositions(IBits liveDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - throw new InvalidOperationException("this method should never be called"); + throw IllegalStateException.Create("this method should never be called"); } // LUCENENET specific @@ -345,12 +345,12 @@ public override BytesRef Next() public override TermState GetTermState() { - throw new InvalidOperationException("this method should never be called"); + throw IllegalStateException.Create("this method should never be called"); } public override void SeekExact(BytesRef term, TermState state) { - throw new InvalidOperationException("this method should never be called"); + throw IllegalStateException.Create("this method should never be called"); } } } diff --git a/src/Lucene.Net/Search/CachingCollector.cs b/src/Lucene.Net/Search/CachingCollector.cs index e6e61c8b6f..d00e9117d8 100644 --- a/src/Lucene.Net/Search/CachingCollector.cs +++ b/src/Lucene.Net/Search/CachingCollector.cs @@ -510,7 +510,7 @@ internal virtual void ReplayInit(ICollector other) { if (!IsCached) { - throw new InvalidOperationException("cannot replay: cache was cleared because too much RAM was required"); + throw IllegalStateException.Create("cannot replay: cache was cleared because too much RAM was required"); } if (!other.AcceptsDocsOutOfOrder && this.m_other.AcceptsDocsOutOfOrder) diff --git a/src/Lucene.Net/Search/FieldCacheImpl.cs b/src/Lucene.Net/Search/FieldCacheImpl.cs index 0bb93b0ce3..c874c196c6 100644 --- a/src/Lucene.Net/Search/FieldCacheImpl.cs +++ b/src/Lucene.Net/Search/FieldCacheImpl.cs @@ -597,7 +597,7 @@ public virtual FieldCache.Bytes GetBytes(AtomicReader reader, string field, Fiel } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -770,7 +770,7 @@ public virtual FieldCache.Int16s GetInt16s(AtomicReader reader, string field, Fi } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -942,7 +942,7 @@ public virtual FieldCache.Int32s GetInt32s(AtomicReader reader, string field, Fi } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -1237,7 +1237,7 @@ public virtual FieldCache.Singles GetSingles(AtomicReader reader, string field, } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -1403,7 +1403,7 @@ public virtual FieldCache.Int64s GetInt64s(AtomicReader reader, string field, Fi } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -1581,7 +1581,7 @@ public virtual FieldCache.Doubles GetDoubles(AtomicReader reader, string field, } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -1771,7 +1771,7 @@ public virtual SortedDocValues GetTermsIndex(AtomicReader reader, string field, { // we don't try to build a sorted instance from numeric/binary doc // values because dedup can be very costly - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -1937,7 +1937,7 @@ public virtual BinaryDocValues GetTerms(AtomicReader reader, string field, bool } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { @@ -2087,7 +2087,7 @@ public virtual SortedSetDocValues GetDocTermOrds(AtomicReader reader, string fie } else if (info.HasDocValues) { - throw new InvalidOperationException("Type mismatch: " + field + " was indexed as " + info.DocValuesType); + throw IllegalStateException.Create("Type mismatch: " + field + " was indexed as " + info.DocValuesType); } else if (!info.IsIndexed) { diff --git a/src/Lucene.Net/Search/MultiPhraseQuery.cs b/src/Lucene.Net/Search/MultiPhraseQuery.cs index 9cf4060c3d..37105ccf14 100644 --- a/src/Lucene.Net/Search/MultiPhraseQuery.cs +++ b/src/Lucene.Net/Search/MultiPhraseQuery.cs @@ -285,7 +285,7 @@ public override Scorer GetScorer(AtomicReaderContext context, IBits acceptDocs) { // term does exist, but has no positions if (Debugging.AssertsEnabled) Debugging.Assert(termsEnum.Docs(liveDocs, null, DocsFlags.NONE) != null, "termstate found but no term exists in reader"); - throw new InvalidOperationException("field \"" + term.Field + "\" was indexed without position data; cannot run PhraseQuery (term=" + term.Text() + ")"); + throw IllegalStateException.Create("field \"" + term.Field + "\" was indexed without position data; cannot run PhraseQuery (term=" + term.Text() + ")"); } docFreq = termsEnum.DocFreq; @@ -621,7 +621,7 @@ public UnionDocsAndPositionsEnum(IBits liveDocs, AtomicReaderContext context, Te if (postings == null) { // term does exist, but has no positions - throw new InvalidOperationException("field \"" + term.Field + "\" was indexed without position data; cannot run PhraseQuery (term=" + term.Text() + ")"); + throw IllegalStateException.Create("field \"" + term.Field + "\" was indexed without position data; cannot run PhraseQuery (term=" + term.Text() + ")"); } _cost += postings.GetCost(); docsEnums.Add(postings); diff --git a/src/Lucene.Net/Search/PhraseQuery.cs b/src/Lucene.Net/Search/PhraseQuery.cs index 2abe9da7b0..80bdf224a4 100644 --- a/src/Lucene.Net/Search/PhraseQuery.cs +++ b/src/Lucene.Net/Search/PhraseQuery.cs @@ -369,7 +369,7 @@ public override Scorer GetScorer(AtomicReaderContext context, IBits acceptDocs) { if (Debugging.AssertsEnabled) Debugging.Assert(te.SeekExact(t.Bytes), "termstate found but no term exists in reader"); // term does exist, but has no positions - throw new InvalidOperationException("field \"" + t.Field + "\" was indexed without position data; cannot run PhraseQuery (term=" + t.Text() + ")"); + throw IllegalStateException.Create("field \"" + t.Field + "\" was indexed without position data; cannot run PhraseQuery (term=" + t.Text() + ")"); } postingsFreqs[i] = new PostingsAndFreq(postingsEnum, te.DocFreq, (int)outerInstance.positions[i], t); } diff --git a/src/Lucene.Net/Search/ReferenceManager.cs b/src/Lucene.Net/Search/ReferenceManager.cs index c03fe2ffc9..ead73ed612 100644 --- a/src/Lucene.Net/Search/ReferenceManager.cs +++ b/src/Lucene.Net/Search/ReferenceManager.cs @@ -127,7 +127,7 @@ holds on to it as the actual instance. decrements the refcount without a corresponding increment since the RM assigns the new reference before counting down the reference. */ - throw new InvalidOperationException("The managed reference has already closed - this is likely a bug when the reference count is modified outside of the ReferenceManager"); + throw IllegalStateException.Create("The managed reference has already closed - this is likely a bug when the reference count is modified outside of the ReferenceManager"); } } while (true); } diff --git a/src/Lucene.Net/Search/SearcherLifetimeManager.cs b/src/Lucene.Net/Search/SearcherLifetimeManager.cs index 0e96071975..80e40340ed 100644 --- a/src/Lucene.Net/Search/SearcherLifetimeManager.cs +++ b/src/Lucene.Net/Search/SearcherLifetimeManager.cs @@ -347,7 +347,7 @@ protected virtual void Dispose(bool disposing) // Make some effort to catch mis-use: if (_searchers.Count != 0) { - throw new InvalidOperationException("another thread called record while this SearcherLifetimeManager instance was being disposed; not all searchers were disposed"); + throw IllegalStateException.Create("another thread called record while this SearcherLifetimeManager instance was being disposed; not all searchers were disposed"); } } } diff --git a/src/Lucene.Net/Search/SearcherManager.cs b/src/Lucene.Net/Search/SearcherManager.cs index e0fd65d8f9..80308dcb27 100644 --- a/src/Lucene.Net/Search/SearcherManager.cs +++ b/src/Lucene.Net/Search/SearcherManager.cs @@ -176,7 +176,7 @@ public static IndexSearcher GetSearcher(SearcherFactory searcherFactory, IndexRe searcher = searcherFactory.NewSearcher(reader); if (searcher.IndexReader != reader) { - throw new InvalidOperationException("SearcherFactory must wrap exactly the provided reader (got " + searcher.IndexReader + " but expected " + reader + ")"); + throw IllegalStateException.Create("SearcherFactory must wrap exactly the provided reader (got " + searcher.IndexReader + " but expected " + reader + ")"); } success = true; } diff --git a/src/Lucene.Net/Search/SortField.cs b/src/Lucene.Net/Search/SortField.cs index fa180bdd52..53bd37e42d 100644 --- a/src/Lucene.Net/Search/SortField.cs +++ b/src/Lucene.Net/Search/SortField.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; using System; using System.Collections.Generic; using System.IO; @@ -467,10 +467,10 @@ public virtual FieldComparer GetComparer(int numHits, int sortPos) return new FieldComparer.TermValComparer(numHits, field); case SortFieldType.REWRITEABLE: - throw new InvalidOperationException("SortField needs to be rewritten through Sort.rewrite(..) and SortField.rewrite(..)"); + throw IllegalStateException.Create("SortField needs to be rewritten through Sort.Rewrite(..) and SortField.Rewrite(..)"); default: - throw new InvalidOperationException("Illegal sort type: " + type); + throw IllegalStateException.Create("Illegal sort type: " + type); } } diff --git a/src/Lucene.Net/Search/Spans/SpanTermQuery.cs b/src/Lucene.Net/Search/Spans/SpanTermQuery.cs index 35d70118e3..dd374e135d 100644 --- a/src/Lucene.Net/Search/Spans/SpanTermQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanTermQuery.cs @@ -164,7 +164,7 @@ public override Spans GetSpans(AtomicReaderContext context, IBits acceptDocs, ID else { // term does exist, but has no positions - throw new InvalidOperationException("field \"" + m_term.Field + "\" was indexed without position data; cannot run SpanTermQuery (term=" + m_term.Text() + ")"); + throw IllegalStateException.Create("field \"" + m_term.Field + "\" was indexed without position data; cannot run SpanTermQuery (term=" + m_term.Text() + ")"); } } } diff --git a/src/Lucene.Net/Store/ByteBufferIndexInput.cs b/src/Lucene.Net/Store/ByteBufferIndexInput.cs index bdcff227c2..f9741d0c0d 100644 --- a/src/Lucene.Net/Store/ByteBufferIndexInput.cs +++ b/src/Lucene.Net/Store/ByteBufferIndexInput.cs @@ -278,7 +278,7 @@ public ByteBufferIndexInput Slice(string sliceDescription, long offset, long len EnsureOpen(); if (isClone) // well we could, but this is stupid { - throw new InvalidOperationException("cannot slice() " + sliceDescription + " from a cloned IndexInput: " + this); + throw IllegalStateException.Create("cannot Slice() " + sliceDescription + " from a cloned IndexInput: " + this); } ByteBufferIndexInput clone = BuildSlice(offset, length); clone.sliceDescription = sliceDescription; diff --git a/src/Lucene.Net/Store/CheckSumIndexInput.cs b/src/Lucene.Net/Store/CheckSumIndexInput.cs index 16dcc2f307..ab9a0920e7 100644 --- a/src/Lucene.Net/Store/CheckSumIndexInput.cs +++ b/src/Lucene.Net/Store/CheckSumIndexInput.cs @@ -51,7 +51,7 @@ public override void Seek(long pos) long skip = pos - GetFilePointer(); if (skip < 0) { - throw new InvalidOperationException(this.GetType() + " cannot seek backwards"); + throw IllegalStateException.Create(this.GetType() + " cannot seek backwards"); } SkipBytes(skip); } diff --git a/src/Lucene.Net/Store/CompoundFileWriter.cs b/src/Lucene.Net/Store/CompoundFileWriter.cs index 51785b7dbb..9f2c6fd782 100644 --- a/src/Lucene.Net/Store/CompoundFileWriter.cs +++ b/src/Lucene.Net/Store/CompoundFileWriter.cs @@ -151,7 +151,7 @@ public void Dispose() { if (pendingEntries.Count > 0 || outputTaken) { - throw new InvalidOperationException("CFS has pending open files"); + throw IllegalStateException.Create("CFS has pending open files"); } closed = true; // open the compound stream diff --git a/src/Lucene.Net/Store/FSLockFactory.cs b/src/Lucene.Net/Store/FSLockFactory.cs index 646458cf21..96536d0dbb 100644 --- a/src/Lucene.Net/Store/FSLockFactory.cs +++ b/src/Lucene.Net/Store/FSLockFactory.cs @@ -41,7 +41,7 @@ protected internal void SetLockDir(DirectoryInfo lockDir) { if (this.m_lockDir != null) { - throw new InvalidOperationException("You can set the lock directory for this factory only once."); + throw IllegalStateException.Create("You can set the lock directory for this factory only once."); } this.m_lockDir = lockDir; } diff --git a/src/Lucene.Net/Store/LockVerifyServer.cs b/src/Lucene.Net/Store/LockVerifyServer.cs index d562a2ad5c..edfa6f03c5 100644 --- a/src/Lucene.Net/Store/LockVerifyServer.cs +++ b/src/Lucene.Net/Store/LockVerifyServer.cs @@ -150,7 +150,7 @@ public override void Run() if (currentLock != -1) { lockedID[0] = -2; - throw new InvalidOperationException("id " + id + " got lock, but " + currentLock + " already holds the lock"); + throw IllegalStateException.Create("id " + id + " got lock, but " + currentLock + " already holds the lock"); } lockedID[0] = id; break; @@ -160,7 +160,7 @@ public override void Run() if (currentLock != id) { lockedID[0] = -2; - throw new InvalidOperationException("id " + id + " released the lock, but " + currentLock + " is the one holding the lock"); + throw IllegalStateException.Create("id " + id + " released the lock, but " + currentLock + " is the one holding the lock"); } lockedID[0] = -1; break; diff --git a/src/Lucene.Net/Store/VerifyingLockFactory.cs b/src/Lucene.Net/Store/VerifyingLockFactory.cs index 188352beea..bf9b71b888 100644 --- a/src/Lucene.Net/Store/VerifyingLockFactory.cs +++ b/src/Lucene.Net/Store/VerifyingLockFactory.cs @@ -56,7 +56,7 @@ private void Verify(byte message) int ret = outerInstance.stream.ReadByte(); if (ret < 0) { - throw new InvalidOperationException("Lock server died because of locking error."); + throw IllegalStateException.Create("Lock server died because of locking error."); } if (ret != message) { diff --git a/src/Lucene.Net/Support/ExceptionHandling/Exceptions/RuntimeExceptions/IllegalStateException.cs b/src/Lucene.Net/Support/ExceptionHandling/Exceptions/RuntimeExceptions/IllegalStateException.cs index b4060ff3d6..3b1276d5ab 100644 --- a/src/Lucene.Net/Support/ExceptionHandling/Exceptions/RuntimeExceptions/IllegalStateException.cs +++ b/src/Lucene.Net/Support/ExceptionHandling/Exceptions/RuntimeExceptions/IllegalStateException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.Serialization; namespace Lucene @@ -39,18 +40,22 @@ namespace Lucene #endif internal class IllegalStateException : InvalidOperationException { + [Obsolete("Use IllegalStateException.Create() instead.", error: true)] public IllegalStateException() { } + [Obsolete("Use IllegalStateException.Create() instead.", error: true)] public IllegalStateException(string message) : base(message) { } + [Obsolete("Use IllegalStateException.Create() instead.", error: true)] public IllegalStateException(string message, Exception innerException) : base(message, innerException) { } + [Obsolete("Use IllegalStateException.Create() instead.", error: true)] public IllegalStateException(Exception cause) : base(cause?.ToString(), cause) { @@ -67,5 +72,22 @@ protected IllegalStateException(SerializationInfo info, StreamingContext context { } #endif + + // Static factory methods + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Exception Create() => new InvalidOperationException(); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Exception Create(string message) => new InvalidOperationException(message); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Exception Create(string message, Exception innerException) => new InvalidOperationException(message, innerException); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Exception Create(Exception cause) => new InvalidOperationException(cause.Message, cause); } } diff --git a/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs b/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs index e95abbab14..5e173b40dd 100644 --- a/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs +++ b/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs @@ -267,7 +267,7 @@ public State Complete() { if (this.stateRegistry == null) { - throw new InvalidOperationException(); + throw IllegalStateException.Create(); } if (root.HasChildren) diff --git a/src/Lucene.Net/Util/BytesRef.cs b/src/Lucene.Net/Util/BytesRef.cs index a12dc2480c..25fabb1982 100644 --- a/src/Lucene.Net/Util/BytesRef.cs +++ b/src/Lucene.Net/Util/BytesRef.cs @@ -367,31 +367,31 @@ public bool IsValid() { if (Bytes == null) { - throw new InvalidOperationException("bytes is null"); + throw IllegalStateException.Create("bytes is null"); } if (Length < 0) { - throw new InvalidOperationException("length is negative: " + Length); + throw IllegalStateException.Create("length is negative: " + Length); } if (Length > Bytes.Length) { - throw new InvalidOperationException("length is out of bounds: " + Length + ",bytes.length=" + Bytes.Length); + throw IllegalStateException.Create("length is out of bounds: " + Length + ",bytes.length=" + Bytes.Length); } if (Offset < 0) { - throw new InvalidOperationException("offset is negative: " + Offset); + throw IllegalStateException.Create("offset is negative: " + Offset); } if (Offset > Bytes.Length) { - throw new InvalidOperationException("offset out of bounds: " + Offset + ",bytes.length=" + Bytes.Length); + throw IllegalStateException.Create("offset out of bounds: " + Offset + ",bytes.length=" + Bytes.Length); } if (Offset + Length < 0) { - throw new InvalidOperationException("offset+length is negative: offset=" + Offset + ",length=" + Length); + throw IllegalStateException.Create("offset+length is negative: offset=" + Offset + ",length=" + Length); } if (Offset + Length > Bytes.Length) { - throw new InvalidOperationException("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",bytes.length=" + Bytes.Length); + throw IllegalStateException.Create("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",bytes.length=" + Bytes.Length); } return true; } diff --git a/src/Lucene.Net/Util/CharsRef.cs b/src/Lucene.Net/Util/CharsRef.cs index 405221e6f5..f24deafbcc 100644 --- a/src/Lucene.Net/Util/CharsRef.cs +++ b/src/Lucene.Net/Util/CharsRef.cs @@ -407,31 +407,31 @@ public bool IsValid() { if (Chars == null) { - throw new InvalidOperationException("chars is null"); + throw IllegalStateException.Create("chars is null"); } if (Length < 0) { - throw new InvalidOperationException("Length is negative: " + Length); + throw IllegalStateException.Create("Length is negative: " + Length); } if (Length > Chars.Length) { - throw new InvalidOperationException("Length is out of bounds: " + Length + ",chars.Length=" + Chars.Length); + throw IllegalStateException.Create("Length is out of bounds: " + Length + ",chars.Length=" + Chars.Length); } if (Offset < 0) { - throw new InvalidOperationException("offset is negative: " + Offset); + throw IllegalStateException.Create("offset is negative: " + Offset); } if (Offset > Chars.Length) { - throw new InvalidOperationException("offset out of bounds: " + Offset + ",chars.Length=" + Chars.Length); + throw IllegalStateException.Create("offset out of bounds: " + Offset + ",chars.Length=" + Chars.Length); } if (Offset + Length < 0) { - throw new InvalidOperationException("offset+Length is negative: offset=" + Offset + ",Length=" + Length); + throw IllegalStateException.Create("offset+Length is negative: offset=" + Offset + ",Length=" + Length); } if (Offset + Length > Chars.Length) { - throw new InvalidOperationException("offset+Length out of bounds: offset=" + Offset + ",Length=" + Length + ",chars.Length=" + Chars.Length); + throw IllegalStateException.Create("offset+Length out of bounds: offset=" + Offset + ",Length=" + Length + ",chars.Length=" + Chars.Length); } return true; } diff --git a/src/Lucene.Net/Util/Fst/FST.cs b/src/Lucene.Net/Util/Fst/FST.cs index c566bc72ef..f2b2d7e678 100644 --- a/src/Lucene.Net/Util/Fst/FST.cs +++ b/src/Lucene.Net/Util/Fst/FST.cs @@ -286,7 +286,7 @@ public FST(DataInput @in, Outputs outputs, int maxBlockBits) 0 => FST.INPUT_TYPE.BYTE1, 1 => FST.INPUT_TYPE.BYTE2, 2 => FST.INPUT_TYPE.BYTE4, - _ => throw new InvalidOperationException("invalid input type " + t), + _ => throw IllegalStateException.Create("invalid input type " + t), }; if (packed) { @@ -347,7 +347,7 @@ internal void Finish(long newStartNode) { if (startNode != -1) { - throw new InvalidOperationException("already finished"); + throw IllegalStateException.Create("already finished"); } if (newStartNode == FST.FINAL_END_NODE && !EqualityComparer.Default.Equals(emptyOutput, default)) { @@ -482,15 +482,15 @@ public void Save(DataOutput @out) { if (startNode == -1) { - throw new InvalidOperationException("call finish first"); + throw IllegalStateException.Create("call finish first"); } if (nodeAddress != null) { - throw new InvalidOperationException("cannot save an FST pre-packed FST; it must first be packed"); + throw IllegalStateException.Create("cannot save an FST pre-packed FST; it must first be packed"); } if (packed && !(nodeRefToAddress is PackedInt32s.Mutable)) { - throw new InvalidOperationException("cannot save a FST which has been loaded from disk "); + throw IllegalStateException.Create("cannot save a FST which has been loaded from disk "); } CodecUtil.WriteHeader(@out, FST.FILE_FORMAT_NAME, FST.VERSION_CURRENT); if (packed) @@ -834,7 +834,7 @@ internal long AddNode(Builder.UnCompiledNode nodeIn) // > 2.1B nodes when packing: if (nodeAddress != null && nodeCount == int.MaxValue) { - throw new InvalidOperationException("cannot create a packed FST with more than 2.1 billion nodes"); + throw IllegalStateException.Create("cannot create a packed FST with more than 2.1 billion nodes"); } nodeCount++; diff --git a/src/Lucene.Net/Util/IntsRef.cs b/src/Lucene.Net/Util/IntsRef.cs index 4f9c7d619d..a98c482d90 100644 --- a/src/Lucene.Net/Util/IntsRef.cs +++ b/src/Lucene.Net/Util/IntsRef.cs @@ -262,31 +262,31 @@ public bool IsValid() { if (ints == null) { - throw new InvalidOperationException("ints is null"); + throw IllegalStateException.Create("ints is null"); } if (Length < 0) { - throw new InvalidOperationException("length is negative: " + Length); + throw IllegalStateException.Create("length is negative: " + Length); } if (Length > ints.Length) { - throw new InvalidOperationException("length is out of bounds: " + Length + ",ints.length=" + Int32s.Length); + throw IllegalStateException.Create("length is out of bounds: " + Length + ",ints.length=" + Int32s.Length); } if (Offset < 0) { - throw new InvalidOperationException("offset is negative: " + Offset); + throw IllegalStateException.Create("offset is negative: " + Offset); } if (Offset > ints.Length) { - throw new InvalidOperationException("offset out of bounds: " + Offset + ",ints.length=" + Int32s.Length); + throw IllegalStateException.Create("offset out of bounds: " + Offset + ",ints.length=" + Int32s.Length); } if (Offset + Length < 0) { - throw new InvalidOperationException("offset+length is negative: offset=" + Offset + ",length=" + Length); + throw IllegalStateException.Create("offset+length is negative: offset=" + Offset + ",length=" + Length); } if (Offset + Length > Int32s.Length) { - throw new InvalidOperationException("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",ints.length=" + Int32s.Length); + throw IllegalStateException.Create("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",ints.length=" + Int32s.Length); } return true; } diff --git a/src/Lucene.Net/Util/LongsRef.cs b/src/Lucene.Net/Util/LongsRef.cs index 9d1faf217f..46a51d6c30 100644 --- a/src/Lucene.Net/Util/LongsRef.cs +++ b/src/Lucene.Net/Util/LongsRef.cs @@ -262,31 +262,31 @@ public bool IsValid() { if (longs == null) { - throw new InvalidOperationException("longs is null"); + throw IllegalStateException.Create("longs is null"); } if (Length < 0) { - throw new InvalidOperationException("length is negative: " + Length); + throw IllegalStateException.Create("length is negative: " + Length); } if (Length > longs.Length) { - throw new InvalidOperationException("length is out of bounds: " + Length + ",longs.length=" + longs.Length); + throw IllegalStateException.Create("length is out of bounds: " + Length + ",longs.length=" + longs.Length); } if (Offset < 0) { - throw new InvalidOperationException("offset is negative: " + Offset); + throw IllegalStateException.Create("offset is negative: " + Offset); } if (Offset > longs.Length) { - throw new InvalidOperationException("offset out of bounds: " + Offset + ",longs.length=" + longs.Length); + throw IllegalStateException.Create("offset out of bounds: " + Offset + ",longs.length=" + longs.Length); } if (Offset + Length < 0) { - throw new InvalidOperationException("offset+length is negative: offset=" + Offset + ",length=" + Length); + throw IllegalStateException.Create("offset+length is negative: offset=" + Offset + ",length=" + Length); } if (Offset + Length > longs.Length) { - throw new InvalidOperationException("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",longs.length=" + longs.Length); + throw IllegalStateException.Create("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",longs.length=" + longs.Length); } return true; } diff --git a/src/Lucene.Net/Util/Packed/AbstractAppendingLongBuffer.cs b/src/Lucene.Net/Util/Packed/AbstractAppendingLongBuffer.cs index 0feb6b602b..3a6b0026f3 100644 --- a/src/Lucene.Net/Util/Packed/AbstractAppendingLongBuffer.cs +++ b/src/Lucene.Net/Util/Packed/AbstractAppendingLongBuffer.cs @@ -83,7 +83,7 @@ public void Add(long l) { if (pending == null) { - throw new InvalidOperationException("this buffer is frozen"); + throw IllegalStateException.Create("this buffer is frozen"); } if (pendingOff == pending.Length) { diff --git a/src/Lucene.Net/Util/Packed/AbstractBlockPackedWriter.cs b/src/Lucene.Net/Util/Packed/AbstractBlockPackedWriter.cs index 9d3d85f2bf..bda039dbb4 100644 --- a/src/Lucene.Net/Util/Packed/AbstractBlockPackedWriter.cs +++ b/src/Lucene.Net/Util/Packed/AbstractBlockPackedWriter.cs @@ -88,7 +88,7 @@ private void CheckNotFinished() { if (m_finished) { - throw new InvalidOperationException("Already finished"); + throw IllegalStateException.Create("Already finished"); } } @@ -111,7 +111,7 @@ internal virtual void AddBlockOfZeros() CheckNotFinished(); if (m_off != 0 && m_off != m_values.Length) { - throw new InvalidOperationException("" + m_off); + throw IllegalStateException.Create("" + m_off); } if (m_off == m_values.Length) { diff --git a/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs b/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs index 119e6c0132..3c9c011526 100644 --- a/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs +++ b/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs @@ -54,7 +54,7 @@ public override long Get(int index) } catch (Exception e) when (e.IsIOException()) { - throw new InvalidOperationException("failed", e); + throw IllegalStateException.Create("failed", e); } } diff --git a/src/Lucene.Net/Util/Packed/DirectPackedReader.cs b/src/Lucene.Net/Util/Packed/DirectPackedReader.cs index ff907a42bc..74092c87f3 100644 --- a/src/Lucene.Net/Util/Packed/DirectPackedReader.cs +++ b/src/Lucene.Net/Util/Packed/DirectPackedReader.cs @@ -111,7 +111,7 @@ public override long Get(int index) } catch (Exception ioe) when (ioe.IsIOException()) { - throw new InvalidOperationException("failed", ioe); + throw IllegalStateException.Create("failed", ioe); } } diff --git a/src/Lucene.Net/Util/Packed/EliasFanoDecoder.cs b/src/Lucene.Net/Util/Packed/EliasFanoDecoder.cs index acdf86e049..80381c5dcc 100644 --- a/src/Lucene.Net/Util/Packed/EliasFanoDecoder.cs +++ b/src/Lucene.Net/Util/Packed/EliasFanoDecoder.cs @@ -78,11 +78,11 @@ public virtual long CurrentIndex() { if (efIndex < 0) { - throw new InvalidOperationException("index before sequence"); + throw IllegalStateException.Create("index before sequence"); } if (efIndex >= numEncoded) { - throw new InvalidOperationException("index after sequence"); + throw IllegalStateException.Create("index after sequence"); } return efIndex; } diff --git a/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs b/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs index ff858e6c0f..929910997e 100644 --- a/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs +++ b/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs @@ -239,7 +239,7 @@ public virtual void EncodeNext(long x) { if (numEncoded >= numValues) { - throw new InvalidOperationException("encodeNext called more than " + numValues + " times."); + throw IllegalStateException.Create("EncodeNext() called more than " + numValues + " times."); } if (lastEncoded > x) { diff --git a/src/Lucene.Net/Util/Packed/PackedInts.cs b/src/Lucene.Net/Util/Packed/PackedInts.cs index f22bb77999..a908019738 100644 --- a/src/Lucene.Net/Util/Packed/PackedInts.cs +++ b/src/Lucene.Net/Util/Packed/PackedInts.cs @@ -1123,7 +1123,7 @@ public override long Get(int index) } catch (Exception e) when (e.IsIOException()) { - throw new InvalidOperationException("failed", e); + throw IllegalStateException.Create("failed", e); } } return result; diff --git a/src/Lucene.Net/Util/PagedBytes.cs b/src/Lucene.Net/Util/PagedBytes.cs index edf9f2c258..1a562281f0 100644 --- a/src/Lucene.Net/Util/PagedBytes.cs +++ b/src/Lucene.Net/Util/PagedBytes.cs @@ -244,11 +244,11 @@ public Reader Freeze(bool trim) { if (frozen) { - throw new InvalidOperationException("already frozen"); + throw IllegalStateException.Create("already frozen"); } if (didSkipBytes) { - throw new InvalidOperationException("cannot freeze when copy(BytesRef, BytesRef) was used"); + throw IllegalStateException.Create("cannot freeze when Copy(BytesRef, BytesRef) was used"); } if (trim && upto < blockSize) { @@ -501,7 +501,7 @@ public PagedBytesDataInput GetDataInput() { if (!frozen) { - throw new InvalidOperationException("must call Freeze() before GetDataInput()"); + throw IllegalStateException.Create("must call Freeze() before GetDataInput()"); } return new PagedBytesDataInput(this); } @@ -517,7 +517,7 @@ public PagedBytesDataOutput GetDataOutput() { if (frozen) { - throw new InvalidOperationException("cannot get DataOutput after Freeze()"); + throw IllegalStateException.Create("cannot get DataOutput after Freeze()"); } return new PagedBytesDataOutput(this); } diff --git a/src/Lucene.Net/Util/RefCount.cs b/src/Lucene.Net/Util/RefCount.cs index 9750997fe5..c02f440562 100644 --- a/src/Lucene.Net/Util/RefCount.cs +++ b/src/Lucene.Net/Util/RefCount.cs @@ -71,7 +71,7 @@ public void DecRef() } else if (rc < 0) { - throw new InvalidOperationException("too many DecRef() calls: refCount is " + rc + " after decrement"); + throw IllegalStateException.Create("too many DecRef() calls: refCount is " + rc + " after decrement"); } }