This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 3ddf3dfce34281fc746ec99cd0d6d0ae2f3fc002 Author: Shad Storhaug <[email protected]> AuthorDate: Sat Aug 22 15:24:56 2020 +0700 Codecs: Reverted term vectors readers to use InvalidOperationException always instead of AssertionException only when assert is enabled --- .../SimpleText/SimpleTextTermVectorsReader.cs | 14 ++++++++++++-- .../Codecs/Lucene3x/Lucene3xTermVectorsReader.cs | 12 +++++++++++- .../Codecs/Lucene40/Lucene40TermVectorsReader.cs | 12 +++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs index 729d5b4..edbeccb 100644 --- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs +++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs @@ -540,8 +540,18 @@ namespace Lucene.Net.Codecs.SimpleText public override int NextPosition() { - if (Debugging.AssertsEnabled) Debugging.Assert((_positions != null && _nextPos < _positions.Length) || - _startOffsets != null && _nextPos < _startOffsets.Length); + //if (Debugging.AssertsEnabled) Debugging.Assert((_positions != null && _nextPos < _positions.Length) || + // _startOffsets != null && _nextPos < _startOffsets.Length); + + // LUCENENET: The above assertion was for control flow when testing. In Java, it would throw an AssertionError, which is + // caught by the BaseTermVectorsFormatTestCase.assertEquals(RandomTokenStream tk, FieldType ft, Terms terms) method in the + // part that is checking for an error after reading to the end of the enumerator. + + // In .NET it is more natural to throw an InvalidOperationException in this case, since we would potentially get an + // 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"); if (_positions != null) { diff --git a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs index 5e23d2c..8f3d99b 100644 --- a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs +++ b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xTermVectorsReader.cs @@ -740,7 +740,17 @@ namespace Lucene.Net.Codecs.Lucene3x public override int NextPosition() { - if (Debugging.AssertsEnabled) Debugging.Assert((positions != null && nextPos < positions.Length) || startOffsets != null && nextPos < startOffsets.Length); + //if (Debugging.AssertsEnabled) Debugging.Assert((positions != null && nextPos < positions.Length) || startOffsets != null && nextPos < startOffsets.Length); + + // LUCENENET: The above assertion was for control flow when testing. In Java, it would throw an AssertionError, which is + // caught by the BaseTermVectorsFormatTestCase.assertEquals(RandomTokenStream tk, FieldType ft, Terms terms) method in the + // part that is checking for an error after reading to the end of the enumerator. + + // In .NET it is more natural to throw an InvalidOperationException in this case, since we would potentially get an + // 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"); if (positions != null) { diff --git a/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs b/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs index d58a59d..1b1a970 100644 --- a/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs +++ b/src/Lucene.Net/Codecs/Lucene40/Lucene40TermVectorsReader.cs @@ -733,7 +733,17 @@ namespace Lucene.Net.Codecs.Lucene40 public override int NextPosition() { - if (Debugging.AssertsEnabled) Debugging.Assert((positions != null && nextPos < positions.Length) || startOffsets != null && nextPos < startOffsets.Length); + //if (Debugging.AssertsEnabled) Debugging.Assert((positions != null && nextPos < positions.Length) || startOffsets != null && nextPos < startOffsets.Length); + + // LUCENENET: The above assertion was for control flow when testing. In Java, it would throw an AssertionError, which is + // caught by the BaseTermVectorsFormatTestCase.assertEquals(RandomTokenStream tk, FieldType ft, Terms terms) method in the + // part that is checking for an error after reading to the end of the enumerator. + + // In .NET it is more natural to throw an InvalidOperationException in this case, since we would potentially get an + // 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"); if (positions != null) {
