Skip to content

Commit

Permalink
SWEEP: Reviewed all new instances of AssertionError in Lucene and rep…
Browse files Browse the repository at this point in the history
…laced the exception that is thrown in Lucene.NET with Lucene.Net.Diagnostics.AssertionException (see apache#446).
  • Loading branch information
NightOwl888 committed Apr 14, 2021
1 parent 61e78c4 commit bd56fcb
Show file tree
Hide file tree
Showing 33 changed files with 80 additions and 68 deletions.
3 changes: 2 additions & 1 deletion src/Lucene.Net.Benchmark/ByTask/Feeds/DocMaker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using J2N.Threading.Atomic;
using Lucene.Net.Benchmarks.ByTask.Utils;
using Lucene.Net.Diagnostics;
using Lucene.Net.Documents;
using Lucene.Net.Util;
using System;
Expand Down Expand Up @@ -160,7 +161,7 @@ internal Field GetNumericField(string name, NumericType type)
f = new DoubleField(name, 0.0, Field.Store.NO);
break;
default:
throw new InvalidOperationException("Cannot get here");
throw new AssertionException("Cannot get here");
}
if (reuseFields)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Lucene.Net.Codecs/DiskDV/DiskDocValuesProducer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lucene.Net.Codecs.Lucene45;
using Lucene.Net.Codecs.Lucene45;
using Lucene.Net.Diagnostics;
using Lucene.Net.Index;
using Lucene.Net.Store;
using Lucene.Net.Util.Packed;
Expand Down Expand Up @@ -42,7 +43,7 @@ protected override MonotonicBlockPackedReader GetAddressInstance(IndexInput data
protected override MonotonicBlockPackedReader GetIntervalInstance(IndexInput data, FieldInfo field,
BinaryEntry bytes)
{
throw new InvalidOperationException(); // LUCENENET NOTE: This was AssertionError in Lucene
throw new AssertionException();
}

protected override MonotonicBlockPackedReader GetOrdIndexInstance(IndexInput data, FieldInfo field,
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private NumericDocValues LoadNumeric(NumericEntry entry)
}

default:
throw new InvalidOperationException();
throw new AssertionException();
}
}

Expand Down Expand Up @@ -574,7 +574,7 @@ public override IBits GetDocsWithField(FieldInfo field)
NumericEntry ne = numerics[field.Number];
return GetMissingBits(field.Number, ne.missingOffset, ne.missingBytes);
default:
throw new ArgumentOutOfRangeException();
throw new AssertionException();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private NumericDocValues LoadNumeric(FieldInfo field)
ramBytesUsed.AddAndGet(quotientReader.RamBytesUsed());
return new NumericDocValuesAnonymousClass3(min, mult, quotientReader);
default:
throw new InvalidOperationException();
throw new AssertionException();
}
}

Expand Down Expand Up @@ -691,7 +691,7 @@ public override IBits GetDocsWithField(FieldInfo field)
var ne = numerics[field.Number];
return GetMissingBits(field.Number, ne.missingOffset, ne.missingBytes);
default:
throw new InvalidOperationException();
throw new AssertionException();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal SimpleTextDocValuesReader(SegmentReadState state, string ext)
}
else
{
throw new ArgumentOutOfRangeException();
throw new AssertionException();
}
}

Expand Down Expand Up @@ -577,7 +577,7 @@ public override IBits GetDocsWithField(FieldInfo field)
case DocValuesType.NUMERIC:
return GetNumericDocsWithField(field);
default:
throw new ArgumentOutOfRangeException();
throw new AssertionException();
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Lucene.Net.QueryParser/Surround/Query/ComposedQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Lucene.Net.Diagnostics;
using System;
using System.Collections.Generic;
using System.Text;

Expand Down Expand Up @@ -35,7 +36,7 @@ protected ComposedQuery(IList<SrndQuery> qs, bool operatorInfix, string opName)

protected virtual void Recompose(IList<SrndQuery> queries)
{
if (queries.Count < 2) throw new InvalidOperationException("Too few subqueries");
if (queries.Count < 2) throw new AssertionException("Too few subqueries");
this.m_queries = new List<SrndQuery>(queries);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lucene.Net.Index;
using Lucene.Net.Diagnostics;
using Lucene.Net.Index;
using Lucene.Net.Search.Spans;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -105,7 +106,7 @@ public virtual void AddSpanQuery(Search.Query q)
if (q == SrndQuery.TheEmptyLcnQuery)
return;
if (!(q is SpanQuery))
throw new InvalidOperationException("Expected SpanQuery: " + q.ToString(FieldName));
throw new AssertionException("Expected SpanQuery: " + q.ToString(FieldName));
AddSpanQueryWeighted((SpanQuery)q, q.Boost);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Lucene.Net.QueryParser/Surround/Query/SrndBooleanQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lucene.Net.Search;
using Lucene.Net.Diagnostics;
using Lucene.Net.Search;
using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -40,7 +41,7 @@ public static Search.Query MakeBooleanQuery(
{
if (queries.Count <= 1)
{
throw new InvalidOperationException("Too few subqueries: " + queries.Count);
throw new AssertionException("Too few subqueries: " + queries.Count);
}
BooleanQuery bq = new BooleanQuery();
AddQueriesToBoolean(bq, queries, occur);
Expand Down
3 changes: 1 addition & 2 deletions src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ protected override SortedDocValues GetSortedDocValues(AtomicReaderContext contex
case Selector.MIDDLE_MAX: return new MiddleMaxValue(randomOrds);
case Selector.MIN:
default:
if (Debugging.AssertsEnabled) Debugging.Assert(false);
return null;
throw new AssertionException();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private static void CheckIterator<T>(IEnumerator<T> iterator, long expectedSize,
//try
//{
// iterator.remove();
// throw new InvalidOperationException("broken iterator (supports remove): " + iterator);
// throw new AssertionError("broken iterator (supports remove): " + iterator);
//}
//catch (Exception expected) when (e.IsUnsupportedOperationException())
//{
Expand All @@ -257,7 +257,7 @@ private static void CheckIterator<T>(IEnumerator<T> iterator, long expectedSize,
/*try
{
//iterator.next();
throw new InvalidOperationException("broken iterator (allows next() when hasNext==false) " + iterator);
throw new AssertionError("broken iterator (allows next() when hasNext==false) " + iterator);
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lucene.Net.Codecs.Compressing.Dummy;
using Lucene.Net.Codecs.Compressing.Dummy;
using Lucene.Net.Codecs.Lucene46;
using Lucene.Net.Diagnostics;
using Lucene.Net.Randomized.Generators;
using System;

Expand Down Expand Up @@ -48,7 +49,7 @@ public static CompressingCodec RandomInstance(Random random, int chunkSize, bool
return new DummyCompressingCodec(chunkSize, withSegmentSuffix);

default:
throw new InvalidOperationException();
throw new AssertionException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Lucene.Net.Util;
using System;
using System.Collections.Generic;
using AssertionError = Lucene.Net.Diagnostics.AssertionException;

namespace Lucene.Net.Codecs.Lucene3x
{
Expand All @@ -25,6 +24,8 @@ namespace Lucene.Net.Codecs.Lucene3x
* limitations under the License.
*/

using AssertionError = Lucene.Net.Diagnostics.AssertionException; // LUCENENET TODO: Remove this and go with the AssertionError class?

/// <summary>
/// Writes and Merges Lucene 3.x norms format
/// <para/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lucene.Net.Diagnostics;
using Lucene.Net.Diagnostics;
using Lucene.Net.Index;
using Lucene.Net.Store;
using Lucene.Net.Util;
Expand Down Expand Up @@ -132,7 +132,7 @@ private static sbyte DocValuesByte(DocValuesType type)
}
else
{
throw new InvalidOperationException();
throw new AssertionException();
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Lucene.Net.TestFramework/Index/BaseMergePolicyTestCase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using J2N.Threading.Atomic;
using J2N.Threading.Atomic;
using Lucene.Net.Analysis;
using Lucene.Net.Diagnostics;
using Lucene.Net.Documents;
using Lucene.Net.Index.Extensions;
using Lucene.Net.Store;
Expand Down Expand Up @@ -93,7 +94,7 @@ public override void Merge(IndexWriter writer, MergeTrigger trigger, bool newMer
{
if (!mayMerge.Value && writer.NextMerge() != null)
{
throw new InvalidOperationException();
throw new AssertionException();
}
base.Merge(writer, trigger, newMergesFound);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using AssertionError = Lucene.Net.Diagnostics.AssertionException;
using Console = Lucene.Net.Util.SystemConsole;
using JCG = J2N.Collections.Generic;
#if FEATURE_SERIALIZABLE_EXCEPTIONS
Expand All @@ -38,6 +37,8 @@ namespace Lucene.Net.Store
* limitations under the License.
*/

using AssertionError = Lucene.Net.Diagnostics.AssertionException; // LUCENENET TODO: Remove this and go with AssertionError class or use alias?

/// <summary>
/// Enum for controlling hard disk throttling.
/// Set via <see cref="MockDirectoryWrapper.Throttling"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,7 @@ private void AssertTermsSeekingEquals(string info, Terms leftTerms, Terms rightT
break;

default:
throw new InvalidOperationException();
throw new AssertionException();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void TestParseExamples()
}
catch (Exception t) when (t.IsThrowable())
{
throw new Exception("Could not parse sample file: " + algFile, t);
throw new AssertionException("Could not parse sample file: " + algFile, t);
}
foundFiles = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using NUnit.Framework;
using System;
using System.Globalization;
using AssertionError = Lucene.Net.Diagnostics.AssertionException;

namespace Lucene.Net.Tests.Queries.Function
{
Expand Down Expand Up @@ -53,7 +54,7 @@ private void DoTest(DocValuesType type)
f = new NumericDocValuesField("dv", 0);
break;
default:
throw new InvalidOperationException();
throw new AssertionError();
}
Document document = new Document();
document.Add(id);
Expand Down Expand Up @@ -104,7 +105,7 @@ private void DoTest(DocValuesType type)
vs = new Int64FieldSource("dv");
break;
default:
throw new InvalidOperationException();
throw new AssertionError();
}
FunctionValues values = vs.GetValues(null, leave);
BytesRef bytes = new BytesRef();
Expand All @@ -122,7 +123,7 @@ private void DoTest(DocValuesType type)
}
else
{
throw new InvalidOperationException();
throw new AssertionError();
}

object expected = vals[ids.Int32Val(i)];
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Tests/Index/TestOmitTf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ public virtual void TestBasic()
{
cause = cause.InnerException;
}
if (!(cause is InvalidOperationException))
if (!cause.IsIllegalStateException())
{
throw new InvalidOperationException("Expected an IAE", e);
throw new AssertionException("Expected an IAE", e);
} // else OK because positions are not indexed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private static void ReadField(DataInput @in, StoredFieldVisitor visitor, FieldIn
break;

default:
throw new InvalidOperationException("Unknown type flag: " + bits.ToString("x"));
throw new AssertionException("Unknown type flag: " + bits.ToString("x"));
}
}

Expand All @@ -252,7 +252,7 @@ private static void SkipField(DataInput @in, int bits)
break;

default:
throw new InvalidOperationException("Unknown type flag: " + bits.ToString("x"));
throw new AssertionException("Unknown type flag: " + bits.ToString("x"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using J2N;
using J2N;
using Lucene.Net.Codecs.Lucene40;
using Lucene.Net.Diagnostics;
using Lucene.Net.Documents;
Expand Down Expand Up @@ -358,7 +358,7 @@ public override void WriteField(FieldInfo info, IIndexableField field)
bufferedDocs.WriteInt64(BitConversion.DoubleToInt64Bits(field.GetDoubleValue().Value));
break;
default:
throw new Exception("Cannot get here");
throw new AssertionException("Cannot get here");
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Lucene.Net/Codecs/Lucene3x/Lucene3xNormsProducer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using J2N.Runtime.CompilerServices;
using J2N.Runtime.CompilerServices;
using J2N.Threading.Atomic;
using Lucene.Net.Diagnostics;
using System;
Expand Down Expand Up @@ -269,22 +269,22 @@ public override NumericDocValues GetNumeric(FieldInfo field)

public override BinaryDocValues GetBinary(FieldInfo field)
{
throw new InvalidOperationException();
throw new AssertionException();
}

public override SortedDocValues GetSorted(FieldInfo field)
{
throw new InvalidOperationException();
throw new AssertionException();
}

public override SortedSetDocValues GetSortedSet(FieldInfo field)
{
throw new InvalidOperationException();
throw new AssertionException();
}

public override IBits GetDocsWithField(FieldInfo field)
{
throw new InvalidOperationException();
throw new AssertionException();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Loading

0 comments on commit bd56fcb

Please sign in to comment.