diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs index b0e5d437bd..f708040e2d 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs @@ -1197,7 +1197,7 @@ private string GetAliasValue(int id) { return aliases[id - 1]; } - catch (IndexOutOfRangeException ex) + catch (Exception ex) when (ex.IsIndexOutOfBoundsException()) { throw new ArgumentException("Bad flag alias number:" + id, ex); } diff --git a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie2.cs b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie2.cs index df31f61c6d..38c95c142a 100644 --- a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie2.cs +++ b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie2.cs @@ -1,4 +1,5 @@ using J2N.IO; +using Lucene; using System; using System.Collections.Generic; using System.IO; @@ -142,7 +143,7 @@ public override string GetFully(string key) } } } - catch (ArgumentOutOfRangeException /*x*/) { } + catch (Exception x) when (x.IsIndexOutOfBoundsException()) { } return result.ToString(); } @@ -200,7 +201,7 @@ public override string GetLastOnPath(string key) } } } - catch (ArgumentOutOfRangeException /*x*/) { } + catch (Exception x) when (x.IsIndexOutOfBoundsException()) { } return result.ToString(); } diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharacterUtils.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharacterUtils.cs index 1692ec4080..1b35a9e73e 100644 --- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharacterUtils.cs +++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharacterUtils.cs @@ -47,7 +47,7 @@ public virtual void TestCodePointAtCharSequenceInt() java4.CodePointAt(highSurrogateAt3, 4); fail("string index out of bounds"); } - catch (ArgumentOutOfRangeException) + catch (Exception e) when (e.IsIndexOutOfBoundsException()) { } @@ -60,7 +60,7 @@ public virtual void TestCodePointAtCharSequenceInt() java5.CodePointAt(highSurrogateAt3, 4); fail("string index out of bounds"); } - catch (ArgumentOutOfRangeException) + catch (Exception e) when (e.IsIndexOutOfBoundsException()) { } @@ -110,7 +110,7 @@ public virtual void TestOffsetByCodePoint() var to = java4.OffsetByCodePoints(s, 0, s.Length, index, offset); assertEquals(to, index + offset); } - catch (ArgumentOutOfRangeException) + catch (Exception e) when (e.IsIndexOutOfBoundsException()) { assertTrue((index + offset) < 0 || (index + offset) > s.Length); } @@ -120,14 +120,14 @@ public virtual void TestOffsetByCodePoint() { o = java5.OffsetByCodePoints(s, 0, s.Length, index, offset); } - catch (ArgumentOutOfRangeException) + catch (Exception e) when (e.IsIndexOutOfBoundsException()) { try { Character.OffsetByCodePoints(s, 0, s.Length, index, offset); fail(); } - catch (ArgumentOutOfRangeException) + catch (Exception e2) when (e2.IsIndexOutOfBoundsException()) { // OK } diff --git a/src/Lucene.Net.Tests/Index/TestSegmentReader.cs b/src/Lucene.Net.Tests/Index/TestSegmentReader.cs index 04c9483f4d..cf4fdd04f8 100644 --- a/src/Lucene.Net.Tests/Index/TestSegmentReader.cs +++ b/src/Lucene.Net.Tests/Index/TestSegmentReader.cs @@ -235,9 +235,7 @@ public virtual void TestOutOfBoundsAccess() reader.Document(-1); Assert.Fail(); } -#pragma warning disable 168 - catch (IndexOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { } @@ -246,9 +244,7 @@ public virtual void TestOutOfBoundsAccess() reader.GetTermVectors(-1); Assert.Fail(); } -#pragma warning disable 168 - catch (IndexOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { } @@ -257,9 +253,7 @@ public virtual void TestOutOfBoundsAccess() reader.Document(numDocs); Assert.Fail(); } -#pragma warning disable 168 - catch (IndexOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { } @@ -268,9 +262,7 @@ public virtual void TestOutOfBoundsAccess() reader.GetTermVectors(numDocs); Assert.Fail(); } -#pragma warning disable 168 - catch (IndexOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { } } diff --git a/src/Lucene.Net.Tests/Util/TestCharsRef.cs b/src/Lucene.Net.Tests/Util/TestCharsRef.cs index c2a59b8c8b..1246e3877a 100644 --- a/src/Lucene.Net.Tests/Util/TestCharsRef.cs +++ b/src/Lucene.Net.Tests/Util/TestCharsRef.cs @@ -1,4 +1,4 @@ -using J2N.Text; +using J2N.Text; using Lucene.Net.Attributes; using NUnit.Framework; using System; @@ -133,7 +133,7 @@ public virtual void TestCopyCharsRef() // c.CharAt(-1); // Assert.Fail(); // } - // catch (IndexOutOfRangeException expected) + // catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) // { // // expected exception // } @@ -143,7 +143,7 @@ public virtual void TestCopyCharsRef() // c.CharAt(3); // Assert.Fail(); // } - // catch (IndexOutOfRangeException expected) + // catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) // { // // expected exception // } @@ -162,9 +162,7 @@ public virtual void TestCharSequenceIndexer() var _ = c[-1]; Assert.Fail(); } -#pragma warning disable 168 - catch (ArgumentOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { // expected exception } @@ -174,9 +172,7 @@ public virtual void TestCharSequenceIndexer() var _ = c[3]; Assert.Fail(); } -#pragma warning disable 168 - catch (ArgumentOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { // expected exception } @@ -216,9 +212,7 @@ private void DoTestSequence(ICharSequence c) c.Subsequence(-1, 1 - -1); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } -#pragma warning disable 168 - catch (ArgumentOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { // expected exception } @@ -228,9 +222,7 @@ private void DoTestSequence(ICharSequence c) c.Subsequence(0, -1 - 0); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } -#pragma warning disable 168 - catch (ArgumentOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { // expected exception } @@ -240,9 +232,7 @@ private void DoTestSequence(ICharSequence c) c.Subsequence(0, 4 - 0); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } -#pragma warning disable 168 - catch (ArgumentOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { // expected exception } @@ -252,9 +242,7 @@ private void DoTestSequence(ICharSequence c) c.Subsequence(2, 1 - 2); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } -#pragma warning disable 168 - catch (ArgumentOutOfRangeException expected) -#pragma warning restore 168 + catch (Exception expected) when (expected.IsIndexOutOfBoundsException()) { // expected exception } diff --git a/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs b/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs index 5cb51f477e..d55900295f 100644 --- a/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs +++ b/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs @@ -417,7 +417,7 @@ public static void TestOverflow() pq.Add(3); Assert.Fail(); } - catch (IndexOutOfRangeException) + catch (Exception e) when (e.IsIndexOutOfBoundsException()) { } @@ -434,7 +434,7 @@ public static void TestOverflow() { pq.Add(666); } - catch (IndexOutOfRangeException) + catch (Exception e) when (e.IsIndexOutOfBoundsException()) { } } diff --git a/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs b/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs index e7b12136fe..fd1f8210ff 100644 --- a/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs +++ b/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs @@ -217,9 +217,7 @@ public virtual void TestNewString() Assert.AreEqual(cpString.Substring(rs, rc), str); continue; } -#pragma warning disable 168 - catch (ArgumentOutOfRangeException e1) // LUCENENET specific - changed from IndexOutOfBoundsException to ArgumentOutOfRangeException (.NET convention) -#pragma warning restore 168 + catch (Exception e1) when (e1.IsIndexOutOfBoundsException()) { // Ignored. } diff --git a/src/Lucene.Net/Util/BytesRef.cs b/src/Lucene.Net/Util/BytesRef.cs index 61ad2cea9f..a12dc2480c 100644 --- a/src/Lucene.Net/Util/BytesRef.cs +++ b/src/Lucene.Net/Util/BytesRef.cs @@ -531,7 +531,7 @@ public override string ToString() { return bytesRef.Utf8ToString(); } - catch (IndexOutOfRangeException) + catch (Exception e) when (e.IsIndexOutOfBoundsException()) { return bytesRef.ToString(); }