diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Ar/ArabicAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Ar/ArabicAnalyzer.cs index 29dba1091f..5c0200330c 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Ar/ArabicAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Ar/ArabicAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -72,7 +72,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(ArabicAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Bg/BulgarianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Bg/BulgarianAnalyzer.cs index 58541c9281..68b69a4d9b 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Bg/BulgarianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Bg/BulgarianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -65,7 +65,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(BulgarianAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Br/BrazilianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Br/BrazilianAnalyzer.cs index b6048b88f5..f0c31dc5b0 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Br/BrazilianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Br/BrazilianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -64,7 +64,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Ca/CatalanAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Ca/CatalanAnalyzer.cs index 92457bfe86..376c660c5c 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Ca/CatalanAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Ca/CatalanAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -70,7 +70,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(CatalanAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/NormalizeCharMap.cs b/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/NormalizeCharMap.cs index 7620252446..1a3f906c23 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/NormalizeCharMap.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/NormalizeCharMap.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Diagnostics; using Lucene.Net.Util; using Lucene.Net.Util.Fst; @@ -66,7 +66,7 @@ private NormalizeCharMap(FST map) } //System.out.println("cached " + cachedRootArcs.size() + " root arcs"); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // Bogus FST IOExceptions!! (will never happen) throw new Exception("Should never happen", ioe); @@ -130,7 +130,7 @@ public virtual NormalizeCharMap Build() map = builder.Finish(); pendingPairs.Clear(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // Bogus FST IOExceptions!! (will never happen) throw new Exception("Should never happen", ioe); diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Cjk/CJKAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Cjk/CJKAnalyzer.cs index 6af3a548e4..d3f5a0ecb3 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Cjk/CJKAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Cjk/CJKAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Standard; using Lucene.Net.Analysis.Util; @@ -56,7 +56,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(CJKAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Ckb/SoraniAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Ckb/SoraniAnalyzer.cs index 98230806a3..40b62f8a1d 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Ckb/SoraniAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Ckb/SoraniAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -61,7 +61,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Cz/CzechAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Cz/CzechAnalyzer.cs index 29307f9817..3b6c836939 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Cz/CzechAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Cz/CzechAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -72,7 +72,7 @@ private static CharArraySet LoadDefaultSet() // LUCENENET: Avoid static construc LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Da/DanishAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Da/DanishAnalyzer.cs index 4a2f2171b1..1eecfcc02a 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Da/DanishAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Da/DanishAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -63,7 +63,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/De/GermanAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/De/GermanAnalyzer.cs index 86a8fa3fb2..173c6625fc 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/De/GermanAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/De/GermanAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -99,7 +99,7 @@ private static CharArraySet LoadDefaultSet() // LUCENENET: Avoid static construc LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/El/GreekAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/El/GreekAnalyzer.cs index 2ceab4ef17..97e58e51c7 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/El/GreekAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/El/GreekAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Standard; using Lucene.Net.Analysis.Util; @@ -64,7 +64,7 @@ private static CharArraySet LoadDefaultSet() // LUCENENET: Avoid static construc { return LoadStopwordSet(false, typeof(GreekAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/PorterStemmer.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/PorterStemmer.cs index 2d1b511cd1..72dab04135 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/PorterStemmer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/PorterStemmer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Support; using Lucene.Net.Util; using System; @@ -861,7 +861,7 @@ public virtual bool Stem(int i0) // } // } // } - // catch (IOException e) + // catch (Exception e) when (ex.IsIOException()) // { // Console.WriteLine("error reading " + args[i]); // Console.WriteLine(e.ToString()); diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Es/SpanishAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Es/SpanishAnalyzer.cs index b7b51d394f..c0a69c60db 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Es/SpanishAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Es/SpanishAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -71,7 +71,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Eu/BasqueAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Eu/BasqueAnalyzer.cs index 88fcc3e3e8..8296914570 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Eu/BasqueAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Eu/BasqueAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -58,7 +58,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(BasqueAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Fa/PersianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Fa/PersianAnalyzer.cs index c225756d63..444e2b67b8 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Fa/PersianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Fa/PersianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Ar; using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Standard; @@ -71,7 +71,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(PersianAnalyzer), DEFAULT_STOPWORD_FILE, STOPWORDS_COMMENT); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Fi/FinnishAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Fi/FinnishAnalyzer.cs index 2026df2acd..f950b689a3 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Fi/FinnishAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Fi/FinnishAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -63,7 +63,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Fr/FrenchAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Fr/FrenchAnalyzer.cs index b17e898868..0b5937ed28 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Fr/FrenchAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Fr/FrenchAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -121,7 +121,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Ga/IrishAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Ga/IrishAnalyzer.cs index 5b0c6178f2..e70cea7100 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Ga/IrishAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Ga/IrishAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -75,7 +75,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(IrishAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Gl/GalicianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Gl/GalicianAnalyzer.cs index eff44039f8..341735d118 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Gl/GalicianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Gl/GalicianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -61,7 +61,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hi/HindiAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hi/HindiAnalyzer.cs index 62bc54ecdf..31f3c280ee 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hi/HindiAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hi/HindiAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.In; using Lucene.Net.Analysis.Miscellaneous; @@ -68,7 +68,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(HindiAnalyzer), DEFAULT_STOPWORD_FILE, STOPWORDS_COMMENT); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hu/HungarianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hu/HungarianAnalyzer.cs index b7f69a9450..5bd5ec4f9b 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hu/HungarianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hu/HungarianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -63,7 +63,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs index b175b58867..b0e5d437bd 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs @@ -281,7 +281,7 @@ internal virtual Int32sRef Lookup(FST fst, char[] word, int offset, i return output; } } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.Message, bogus); } @@ -1392,7 +1392,7 @@ internal virtual string CleanInput(string input, StringBuilder reuse) { ApplyMappings(iconv, reuse); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.Message, bogus); } diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Stemmer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Stemmer.cs index 41d31fc438..7047eadf79 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Stemmer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Stemmer.cs @@ -226,7 +226,7 @@ private IList DoStem(char[] word, int length, bool caseVariant) { stems.AddRange(Stem(word, length, -1, -1, -1, 0, true, true, false, false, caseVariant)); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -297,7 +297,7 @@ private CharsRef NewStem(char[] buffer, int length, Int32sRef forms, int formID) { Dictionary.ApplyMappings(dictionary.oconv, scratchSegment); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.Message, bogus); } diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hy/ArmenianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hy/ArmenianAnalyzer.cs index f37d6f33f1..ea4a90894e 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hy/ArmenianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hy/ArmenianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -58,7 +58,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(ArmenianAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Id/IndonesianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Id/IndonesianAnalyzer.cs index e6c8e2c21b..533c536f72 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Id/IndonesianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Id/IndonesianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -54,7 +54,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(IndonesianAnalyzer), DEFAULT_STOPWORD_FILE, "#"); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/It/ItalianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/It/ItalianAnalyzer.cs index 8a0576996c..cbd2b2fee3 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/It/ItalianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/It/ItalianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -78,7 +78,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Lv/LatvianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Lv/LatvianAnalyzer.cs index 23827a4825..46a428af86 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Lv/LatvianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Lv/LatvianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; @@ -61,7 +61,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs index ad02830f82..35fdbb0835 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -81,7 +81,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) @@ -183,7 +183,7 @@ public DutchAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords, CharArr { this.stemdict = builder.Build(); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { throw new Exception("can not build stem dict", ex); } diff --git a/src/Lucene.Net.Analysis.Common/Analysis/No/NorwegianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/No/NorwegianAnalyzer.cs index 90197343e6..3ae5d9878e 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/No/NorwegianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/No/NorwegianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -63,7 +63,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Pt/PortugueseAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Pt/PortugueseAnalyzer.cs index cde1ec8fba..b4b21fad8f 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Pt/PortugueseAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Pt/PortugueseAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -68,7 +68,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Ro/RomanianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Ro/RomanianAnalyzer.cs index bb4b1b7141..1ff76f1837 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Ro/RomanianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Ro/RomanianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -63,7 +63,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(RomanianAnalyzer), DEFAULT_STOPWORD_FILE, STOPWORDS_COMMENT); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Ru/RussianAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Ru/RussianAnalyzer.cs index 836e46b2b5..ac9835f3db 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Ru/RussianAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Ru/RussianAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -83,7 +83,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Sv/SwedishAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Sv/SwedishAnalyzer.cs index ce59fa313a..7e73f70f66 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Sv/SwedishAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Sv/SwedishAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -63,7 +63,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Synonym/SynonymMap.cs b/src/Lucene.Net.Analysis.Common/Analysis/Synonym/SynonymMap.cs index d79074aa44..a337e5b195 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Synonym/SynonymMap.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Synonym/SynonymMap.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.TokenAttributes; using Lucene.Net.Diagnostics; using Lucene.Net.Store; @@ -6,7 +6,6 @@ using Lucene.Net.Util.Fst; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using JCG = J2N.Collections.Generic; @@ -357,9 +356,7 @@ public Parser(bool dedup, Analyzer analyzer) /// public virtual CharsRef Analyze(string text, CharsRef reuse) { - IOException priorException = null; - TokenStream ts = analyzer.GetTokenStream("", text); - try + using (TokenStream ts = analyzer.GetTokenStream("", text)) { var termAtt = ts.AddAttribute(); var posIncAtt = ts.AddAttribute(); @@ -388,14 +385,6 @@ public virtual CharsRef Analyze(string text, CharsRef reuse) } ts.End(); } - catch (IOException e) - { - priorException = e; - } - finally - { - IOUtils.DisposeWhileHandlingException(priorException, ts); - } if (reuse.Length == 0) { throw new ArgumentException("term: " + text + " was completely eliminated by analyzer"); diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Th/ThaiAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Th/ThaiAnalyzer.cs index 64d5278234..2f5501caa6 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Th/ThaiAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Th/ThaiAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 #if FEATURE_BREAKITERATOR using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Standard; @@ -65,7 +65,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(ThaiAnalyzer), DEFAULT_STOPWORD_FILE, STOPWORDS_COMMENT); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Tr/TurkishAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Tr/TurkishAnalyzer.cs index de7e0615c4..a15f3bbb66 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Tr/TurkishAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Tr/TurkishAnalyzer.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.Core; using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Snowball; @@ -63,7 +63,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(false, typeof(TurkishAnalyzer), DEFAULT_STOPWORD_FILE, STOPWORDS_COMMENT); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/DefaultICUTokenizerConfig.cs b/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/DefaultICUTokenizerConfig.cs index ef3444d6cf..c3aa669910 100644 --- a/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/DefaultICUTokenizerConfig.cs +++ b/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/DefaultICUTokenizerConfig.cs @@ -138,7 +138,7 @@ private static RuleBasedBreakIterator ReadBreakIterator(string filename) RuleBasedBreakIterator.GetInstanceFromCompiledRules(@is); return bi; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.Kuromoji/Dict/CharacterDefinition.cs b/src/Lucene.Net.Analysis.Kuromoji/Dict/CharacterDefinition.cs index 2d6b285785..fa4b4a756a 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/Dict/CharacterDefinition.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/Dict/CharacterDefinition.cs @@ -109,7 +109,7 @@ private static CharacterDefinition LoadInstance() // LUCENENET: Avoid static con { return new CharacterDefinition(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Cannot load CharacterDefinition.", ioe); } diff --git a/src/Lucene.Net.Analysis.Kuromoji/Dict/ConnectionCosts.cs b/src/Lucene.Net.Analysis.Kuromoji/Dict/ConnectionCosts.cs index 3845a77253..599c84ad55 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/Dict/ConnectionCosts.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/Dict/ConnectionCosts.cs @@ -78,7 +78,7 @@ private static ConnectionCosts LoadInstance() // LUCENENET: Avoid static constru { return new ConnectionCosts(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Cannot load ConnectionCosts.", ioe); } diff --git a/src/Lucene.Net.Analysis.Kuromoji/Dict/TokenInfoDictionary.cs b/src/Lucene.Net.Analysis.Kuromoji/Dict/TokenInfoDictionary.cs index d278e00f93..181ec6fb1f 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/Dict/TokenInfoDictionary.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/Dict/TokenInfoDictionary.cs @@ -56,7 +56,7 @@ private static TokenInfoDictionary LoadInstance() // LUCENENET: Avoid static con { return new TokenInfoDictionary(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Cannot load TokenInfoDictionary.", ioe); } diff --git a/src/Lucene.Net.Analysis.Kuromoji/Dict/UnknownDictionary.cs b/src/Lucene.Net.Analysis.Kuromoji/Dict/UnknownDictionary.cs index 1353ce3e82..b4f2a6bd33 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/Dict/UnknownDictionary.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/Dict/UnknownDictionary.cs @@ -84,7 +84,7 @@ private static UnknownDictionary LoadInstance() // LUCENENET: Avoid static const { return new UnknownDictionary(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Cannot load UnknownDictionary.", ioe); } diff --git a/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs b/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs index 49a1bc6c2f..cef32b94ee 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs @@ -75,7 +75,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadStopwordSet(true, typeof(JapaneseAnalyzer), "stopwords.txt", "#"); // ignore case } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the distribution (JAR) throw new Exception("Unable to load default stopword set", ex); @@ -94,7 +94,7 @@ private static ISet LoadDefaultStopTagSet() // LUCENENET: Avoid static c } return DEFAULT_STOP_TAGS; } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the distribution (JAR) throw new Exception("Unable to load default stoptag set", ex); diff --git a/src/Lucene.Net.Analysis.Kuromoji/Util/ToStringUtil.cs b/src/Lucene.Net.Analysis.Kuromoji/Util/ToStringUtil.cs index f88421c5bf..5afdb22139 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/Util/ToStringUtil.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/Util/ToStringUtil.cs @@ -258,7 +258,7 @@ public static string GetRomanization(string s) { GetRomanization(result, s); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net.Analysis.Morfologik/Uk/UkrainianMorfologikAnalyzer.cs b/src/Lucene.Net.Analysis.Morfologik/Uk/UkrainianMorfologikAnalyzer.cs index 1e97edb02c..52a36af6d5 100644 --- a/src/Lucene.Net.Analysis.Morfologik/Uk/UkrainianMorfologikAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Morfologik/Uk/UkrainianMorfologikAnalyzer.cs @@ -66,7 +66,7 @@ private static CharArraySet LoadDefaultSet() LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) @@ -166,7 +166,7 @@ private static Dictionary GetDictionary() using var metadataStream = type.FindAndGetManifestResourceStream(DictionaryMetadata.GetExpectedMetadataFileName(dictFile)); return Dictionary.Read(dictStream, metadataStream); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPChunkerFilterFactory.cs b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPChunkerFilterFactory.cs index 53d37503cd..2206ccfb6e 100644 --- a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPChunkerFilterFactory.cs +++ b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPChunkerFilterFactory.cs @@ -65,7 +65,7 @@ public override TokenStream Create(TokenStream input) } return new OpenNLPChunkerFilter(input, chunkerOp); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new ArgumentException(e.ToString(), e); } @@ -81,7 +81,7 @@ public virtual void Inform(IResourceLoader loader) OpenNLPOpsFactory.GetChunkerModel(chunkerModelFile, loader); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new ArgumentException(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPLemmatizerFilterFactory.cs b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPLemmatizerFilterFactory.cs index 5d4b6970b2..43260460db 100644 --- a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPLemmatizerFilterFactory.cs +++ b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPLemmatizerFilterFactory.cs @@ -73,7 +73,7 @@ public override TokenStream Create(TokenStream input) NLPLemmatizerOp lemmatizerOp = OpenNLPOpsFactory.GetLemmatizer(dictionaryFile, lemmatizerModelFile); return new OpenNLPLemmatizerFilter(input, lemmatizerOp); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPPOSFilterFactory.cs b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPPOSFilterFactory.cs index 5f112c2d33..8008c0d3c9 100644 --- a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPPOSFilterFactory.cs +++ b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPPOSFilterFactory.cs @@ -58,7 +58,7 @@ public override TokenStream Create(TokenStream input) { return new OpenNLPPOSFilter(input, OpenNLPOpsFactory.GetPOSTagger(posTaggerModelFile)); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new ArgumentException(e.ToString(), e); } @@ -70,7 +70,7 @@ public virtual void Inform(IResourceLoader loader) { // load and register the read-only model in cache with file/resource name OpenNLPOpsFactory.GetPOSTaggerModel(posTaggerModelFile, loader); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new ArgumentException(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizerFactory.cs b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizerFactory.cs index 22ddd9b06d..0aa103c73a 100644 --- a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizerFactory.cs +++ b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizerFactory.cs @@ -63,7 +63,7 @@ public override Tokenizer Create(AttributeFactory factory, TextReader reader) NLPTokenizerOp tokenizerOp = OpenNLPOpsFactory.GetTokenizer(tokenizerModelFile); return new OpenNLPTokenizer(factory, reader, sentenceOp, tokenizerOp); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.SmartCn/Hhmm/BigramDictionary.cs b/src/Lucene.Net.Analysis.SmartCn/Hhmm/BigramDictionary.cs index 3fa1fb1856..61d54b0671 100644 --- a/src/Lucene.Net.Analysis.SmartCn/Hhmm/BigramDictionary.cs +++ b/src/Lucene.Net.Analysis.SmartCn/Hhmm/BigramDictionary.cs @@ -72,7 +72,7 @@ public static BigramDictionary GetInstance() string dictRoot = AnalyzerProfile.ANALYSIS_DATA_DIR; if (string.IsNullOrEmpty(dictRoot)) { - singleInstance.Load(); + singleInstance.Load(); // LUCENENET: No IOException can happen here } else { @@ -237,7 +237,7 @@ private void Load(string dictRoot) } LoadFromFile(bigramDictPath); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.SmartCn/Hhmm/WordDictionary.cs b/src/Lucene.Net.Analysis.SmartCn/Hhmm/WordDictionary.cs index 2aadb8d3c6..371dbdd2a1 100644 --- a/src/Lucene.Net.Analysis.SmartCn/Hhmm/WordDictionary.cs +++ b/src/Lucene.Net.Analysis.SmartCn/Hhmm/WordDictionary.cs @@ -134,7 +134,7 @@ public virtual void Load(string dctFileRoot) SortEachItems(); // log.info("load dictionary: " + dctFilePath + " total:" + total); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Analysis.SmartCn/SmartChineseAnalyzer.cs b/src/Lucene.Net.Analysis.SmartCn/SmartChineseAnalyzer.cs index 8e2e62c22b..147072271b 100644 --- a/src/Lucene.Net.Analysis.SmartCn/SmartChineseAnalyzer.cs +++ b/src/Lucene.Net.Analysis.SmartCn/SmartChineseAnalyzer.cs @@ -77,7 +77,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons { return LoadDefaultStopWordSet(); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (JAR) diff --git a/src/Lucene.Net.Analysis.Stempel/Pl/PolishAnalyzer.cs b/src/Lucene.Net.Analysis.Stempel/Pl/PolishAnalyzer.cs index 23a025b660..0c49cc7fb2 100644 --- a/src/Lucene.Net.Analysis.Stempel/Pl/PolishAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Stempel/Pl/PolishAnalyzer.cs @@ -77,7 +77,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons LuceneVersion.LUCENE_CURRENT); #pragma warning restore 612, 618 } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (embedded resource) @@ -91,7 +91,7 @@ private static Trie LoadDefaultTable() // LUCENENET: Avoid static constructors ( { return StempelStemmer.Load(typeof(PolishAnalyzer).FindAndGetManifestResourceStream(DEFAULT_STEMMER_FILE)); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { // default set should always be present as it is part of the // distribution (embedded resource) diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/EnwikiContentSource.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/EnwikiContentSource.cs index 07bb721a06..b328f442ba 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Feeds/EnwikiContentSource.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/EnwikiContentSource.cs @@ -209,7 +209,7 @@ public void Run() // To work around a bug in XERCES (XERCESJ-1257), we assume the XML is always UTF8, so we simply provide reader. reader.Parse(new InputSource(IOUtils.GetDecodingReader(localFileIS, Encoding.UTF8))); } - catch (IOException /*ioe*/) + catch (Exception ioe) when (ioe.IsIOException()) { lock (outerInstance) { @@ -243,7 +243,7 @@ public void Run() { throw new Exception(sae.ToString(), sae); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs index 21074b3996..1cf78ffd7a 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs @@ -64,7 +64,7 @@ private void OpenFile() reader.ReadLine(); // skip one line - the header line - already handled that info } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecContentSource.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecContentSource.cs index d31d9c01e0..7bb65c70cf 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecContentSource.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecContentSource.cs @@ -227,7 +227,7 @@ private void DoClose() // LUCENENET specific - separate disposing from closing s { reader?.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (m_verbose) { diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/Parser.cs b/src/Lucene.Net.Benchmark/Support/TagSoup/Parser.cs index 3308e130ca..b6b9cf60da 100644 --- a/src/Lucene.Net.Benchmark/Support/TagSoup/Parser.cs +++ b/src/Lucene.Net.Benchmark/Support/TagSoup/Parser.cs @@ -15,6 +15,7 @@ // The TagSoup parser using J2N.Text; +using Lucene; using Lucene.Net.Support; using Sax; using Sax.Ext; @@ -922,7 +923,7 @@ private void Push(Element e) { theEntityResolver.ResolveEntity(theDoctypePublicId, theDoctypeSystemId); } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { } // Can't be thrown for root I believe. } diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/XMLWriter.cs b/src/Lucene.Net.Benchmark/Support/TagSoup/XMLWriter.cs index d5b4f8f678..6561c42005 100644 --- a/src/Lucene.Net.Benchmark/Support/TagSoup/XMLWriter.cs +++ b/src/Lucene.Net.Benchmark/Support/TagSoup/XMLWriter.cs @@ -13,7 +13,7 @@ // OF ANY KIND, either express or implied; not even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - +using Lucene; using Sax; using Sax.Ext; using Sax.Helpers; @@ -581,7 +581,7 @@ public override void EndDocument() { Flush(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new SAXException(e.Message, e); } @@ -1229,7 +1229,7 @@ private void Write(char c) { output.Write(c); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new SAXException(e.ToString(), e); } @@ -1249,7 +1249,7 @@ private void Write(string s) { output.Write(s); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new SAXException(e.ToString(), e); } diff --git a/src/Lucene.Net.Benchmark/Utils/ExtractReuters.cs b/src/Lucene.Net.Benchmark/Utils/ExtractReuters.cs index c8f62ad646..48a5c72df2 100644 --- a/src/Lucene.Net.Benchmark/Utils/ExtractReuters.cs +++ b/src/Lucene.Net.Benchmark/Utils/ExtractReuters.cs @@ -126,7 +126,7 @@ protected virtual void ExtractFile(FileInfo sgmFile) } } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs b/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs index 01f082c813..e45c9e6dc4 100644 --- a/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs +++ b/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs @@ -91,7 +91,7 @@ public virtual void Create(string id, string title, string time, string body) using TextWriter writer = new StreamWriter(new FileStream(f.FullName, FileMode.Create, FileAccess.Write), Encoding.UTF8); writer.Write(contents.ToString()); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs index bf86ba3732..671604b188 100644 --- a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs +++ b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs @@ -195,7 +195,7 @@ protected override void Dispose(bool disposing) { if (blockOut == null) return; - IOException ioe = null; + Exception ioe = null; // LUCENENET: No need to cast to IOExcpetion try { var blockDirStart = blockOut.GetFilePointer(); @@ -227,7 +227,7 @@ protected override void Dispose(bool disposing) CodecUtil.WriteFooter(indexOut); CodecUtil.WriteFooter(blockOut); } - catch (IOException ioe2) + catch (Exception ioe2) when (ioe2.IsIOException()) { ioe = ioe2; } diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs b/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs index f9a08b54c1..dce0660599 100644 --- a/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs +++ b/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs @@ -1,4 +1,5 @@ using Lucene.Net.Util.Fst; +using System; using System.Collections.Generic; using System.IO; @@ -173,7 +174,7 @@ protected override void Dispose(bool disposing) { if (_output == null) return; - IOException ioe = null; + Exception ioe = null; // LUCENENET: No need to cast to IOExcpetion try { // write field summary @@ -196,7 +197,7 @@ protected override void Dispose(bool disposing) WriteTrailer(_output, dirStart); CodecUtil.WriteFooter(_output); } - catch (IOException ioe2) + catch (Exception ioe2) when (ioe2.IsIOException()) { ioe = ioe2; } diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs index bd67a5bdf6..73c1c5f1f5 100644 --- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs +++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs @@ -468,7 +468,7 @@ public bool MoveNext() { EncodeValues(count); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs index 82aaaf561b..4cfd1a6f73 100644 --- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs +++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs @@ -475,7 +475,7 @@ public override void LookupOrd(int ord, BytesRef result) result.Length = 0; Util.ToBytesRef(output, result); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -499,7 +499,7 @@ public override int LookupTerm(BytesRef key) return (int) -o.Output - 1; } } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -609,7 +609,7 @@ public override void LookupOrd(long ord, BytesRef result) result.Length = 0; Util.ToBytesRef(output, result); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -633,7 +633,7 @@ public override long LookupTerm(BytesRef key) return -o.Output.Value - 1; } } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs index 9e1515deeb..c63fb0edd7 100644 --- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs +++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs @@ -194,7 +194,7 @@ public override long Get(int docId) SimpleTextUtil.ReadLine(_input, _scratch); // read the line telling us if its real or not return (long)((decimal)_field.MinValue + bd); // LUCENENET specific - use decimal rather than BigInteger } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } @@ -235,7 +235,7 @@ public bool Get(int index) SimpleTextUtil.ReadLine(_input, _scratch); // 'T' or 'F' return _scratch.Bytes[_scratch.Offset] == (byte)'T'; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -299,7 +299,7 @@ public override void Get(int docId, BytesRef result) result.Length = len; _input.ReadBytes(result.Bytes, 0, len); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } @@ -357,7 +357,7 @@ public bool Get(int index) SimpleTextUtil.ReadLine(_input, _scratch); // 'T' or 'F' return _scratch.Bytes[_scratch.Offset] == (byte)'T'; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } @@ -419,7 +419,7 @@ public override int GetOrd(int docId) throw e; } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } @@ -456,7 +456,7 @@ public override void LookupOrd(int ord, BytesRef result) result.Length = len; _input.ReadBytes(result.Bytes, 0, len); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } @@ -521,7 +521,7 @@ public override void SetDocument(int docID) _currentOrds = ordList.Length == 0 ? Arrays.Empty() : ordList.Split(',').TrimEnd(); _currentIndex = 0; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } @@ -558,7 +558,7 @@ public override void LookupOrd(long ord, BytesRef result) result.Length = len; _input.ReadBytes(result.Bytes, 0, len); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Demo/IndexFiles.cs b/src/Lucene.Net.Demo/IndexFiles.cs index af988e971b..efae0eb4bd 100644 --- a/src/Lucene.Net.Demo/IndexFiles.cs +++ b/src/Lucene.Net.Demo/IndexFiles.cs @@ -122,7 +122,7 @@ public static void Main(string[] args) DateTime end = DateTime.UtcNow; Console.WriteLine((end - start).TotalMilliseconds + " total milliseconds"); } - catch (IOException e) + catch (Exception e) { Console.WriteLine(" caught a " + e.GetType() + "\n with message: " + e.Message); diff --git a/src/Lucene.Net.Expressions/ExpressionComparator.cs b/src/Lucene.Net.Expressions/ExpressionComparator.cs index 15db756646..8266dcea09 100644 --- a/src/Lucene.Net.Expressions/ExpressionComparator.cs +++ b/src/Lucene.Net.Expressions/ExpressionComparator.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; using Lucene.Net.Index; using Lucene.Net.Queries.Function; using Lucene.Net.Search; @@ -57,7 +57,7 @@ public override void SetScorer(Scorer scorer) context["scorer"] = scorer; scores = source.GetValues(context, readerContext); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Expressions/ScoreFunctionValues.cs b/src/Lucene.Net.Expressions/ScoreFunctionValues.cs index a28bc3f2bd..8eb37f27b5 100644 --- a/src/Lucene.Net.Expressions/ScoreFunctionValues.cs +++ b/src/Lucene.Net.Expressions/ScoreFunctionValues.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; using Lucene.Net.Queries.Function; using Lucene.Net.Queries.Function.DocValues; using Lucene.Net.Search; @@ -46,7 +46,7 @@ public override double DoubleVal(int document) if (Debugging.AssertsEnabled) Debugging.Assert(document == scorer.DocID); return scorer.GetScore(); } - catch (IOException exception) + catch (Exception exception) when (exception.IsIOException()) { throw new Exception(exception.ToString(), exception); } diff --git a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs index 91a63667e8..2c1565c8c5 100644 --- a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs @@ -258,7 +258,7 @@ private MatchingDocs CreateSample(MatchingDocs docs) return new MatchingDocs(docs.Context, sampleDocs, docs.TotalHits, null); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index 91f6a81d46..f919a985d6 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -469,7 +469,7 @@ public virtual string ToString(int max) } sb.Append(i + ": " + category.ToString() + "\n"); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { // LUCENENET TODO: Should we use a 3rd party logging library? diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs index 46ef005e5a..983ebba6f9 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs @@ -186,7 +186,7 @@ public override double DoubleVal(int document) { return scorer.GetScore(); } - catch (IOException exception) + catch (Exception exception) when (exception.IsIOException()) { throw new Exception(exception.ToString(), exception); } diff --git a/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs b/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs index 946852351b..5b8d686c0c 100644 --- a/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs +++ b/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs @@ -65,7 +65,7 @@ public static WeightedTerm[] GetIdfWeightedTerms(Query query, IndexReader reader var idf = (float)(Math.Log((float)totalNumDocs / (double)(docFreq + 1)) + 1.0); t.Weight *= idf; } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { //ignore } diff --git a/src/Lucene.Net.Highlighter/Highlight/TokenSources.cs b/src/Lucene.Net.Highlighter/Highlight/TokenSources.cs index bc9cd26aff..c1f78c3da1 100644 --- a/src/Lucene.Net.Highlighter/Highlight/TokenSources.cs +++ b/src/Lucene.Net.Highlighter/Highlight/TokenSources.cs @@ -341,7 +341,7 @@ public static TokenStream GetTokenStream(string field, string contents, { return analyzer.GetTokenStream(field, contents); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { throw new Exception(ex.ToString(), ex); } diff --git a/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs b/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs index 316dd52dfe..fd11cf581a 100644 --- a/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs +++ b/src/Lucene.Net.Highlighter/PostingsHighlight/PostingsHighlighter.cs @@ -812,7 +812,7 @@ public virtual int CompareTo(OffsetsEnum other) return off.CompareTo(otherOff); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Highlighter/VectorHighlight/FastVectorHighlighter.cs b/src/Lucene.Net.Highlighter/VectorHighlight/FastVectorHighlighter.cs index 2ae421b6bb..e91ac898c6 100644 --- a/src/Lucene.Net.Highlighter/VectorHighlight/FastVectorHighlighter.cs +++ b/src/Lucene.Net.Highlighter/VectorHighlight/FastVectorHighlighter.cs @@ -83,7 +83,7 @@ public virtual FieldQuery GetFieldQuery(Query query) { return new FieldQuery(query, null, phraseHighlight, fieldMatch); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { // should never be thrown when reader is null throw new Exception(e.ToString(), e); diff --git a/src/Lucene.Net.Memory/MemoryIndex.cs b/src/Lucene.Net.Memory/MemoryIndex.cs index 3254a7c5c1..3079b15aad 100644 --- a/src/Lucene.Net.Memory/MemoryIndex.cs +++ b/src/Lucene.Net.Memory/MemoryIndex.cs @@ -252,7 +252,7 @@ public virtual void AddField(string fieldName, string text, Analyzer analyzer) { stream = analyzer.GetTokenStream(fieldName, text); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { throw new Exception(ex.ToString(), ex); } @@ -517,7 +517,7 @@ public virtual void AddField(string fieldName, TokenStream stream, float boost, stream.Dispose(); } } - catch (IOException e2) + catch (Exception e2) when (e2.IsIOException()) { throw new Exception(e2.ToString(), e2); } @@ -561,7 +561,7 @@ public virtual float Search(Query query) float score = scores[0]; return score; } // can never happen (RAMDirectory) - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Misc/Document/LazyDocument.cs b/src/Lucene.Net.Misc/Document/LazyDocument.cs index 8c37ccf0ac..a220c8edd4 100644 --- a/src/Lucene.Net.Misc/Document/LazyDocument.cs +++ b/src/Lucene.Net.Misc/Document/LazyDocument.cs @@ -101,7 +101,7 @@ internal virtual Document GetDocument() { doc = reader.Document(docID, fieldNames); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new InvalidOperationException("unable to load document", ioe); } diff --git a/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs b/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs index b361326102..e0c3480883 100644 --- a/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs +++ b/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs @@ -125,9 +125,9 @@ public static void Main(string[] args) } } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { - Console.WriteLine(ioe.ToString()); + Console.Error.WriteLine(ioe.ToString()); //Console.Write(ioe.StackTrace); } finally @@ -143,9 +143,9 @@ public static void Main(string[] args) cfr.Dispose(); } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { - Console.WriteLine(ioe.ToString()); + Console.Error.WriteLine(ioe.ToString()); //Console.Write(ioe.StackTrace); } } diff --git a/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs b/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs index 136b67f7fd..97d481b7a7 100644 --- a/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs +++ b/src/Lucene.Net.Misc/Index/Sorter/BlockJoinComparatorSource.cs @@ -133,7 +133,7 @@ public override int Compare(int slot1, int slot2) { return Compare(childSlots[slot1], parentSlots[slot1], childSlots[slot2], parentSlots[slot2]); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Misc/Index/Sorter/Sorter.cs b/src/Lucene.Net.Misc/Index/Sorter/Sorter.cs index ddc77a04dc..0ef74153ff 100644 --- a/src/Lucene.Net.Misc/Index/Sorter/Sorter.cs +++ b/src/Lucene.Net.Misc/Index/Sorter/Sorter.cs @@ -299,7 +299,7 @@ public override int Compare(int docID1, int docID2) } return docID1.CompareTo(docID2); // docid order tiebreak } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs index 76b42e16ff..cc479a770f 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs @@ -93,7 +93,7 @@ public override int Int32Val(int doc) return 0; } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("caught exception in function " + outerInstance.GetDescription() + " : doc=" + doc, e); } diff --git a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs index cb72e98b4a..bd00a36d7b 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs @@ -163,7 +163,7 @@ public override float SingleVal(int doc) // a match! return scorer.GetScore(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e); } @@ -204,7 +204,7 @@ public override bool Exists(int doc) // a match! return true; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e); } @@ -216,7 +216,7 @@ public override object ObjectVal(int doc) { return Exists(doc) ? scorer.GetScore() : (float?)null; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e); } @@ -268,7 +268,7 @@ public override ValueFiller GetValueFiller() mutableValue.Value = scorer.GetScore(); mutableValue.Exists = true; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e); } diff --git a/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs index d1173d23fe..1096cb6e96 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs @@ -158,7 +158,7 @@ public override float SingleVal(int doc) // a match! return similarity.Tf(docs.Freq); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("caught exception in function " + outerInstance.GetDescription() + " : doc=" + doc, e); } diff --git a/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs index 39d217bc6c..43e6c6c2ad 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs @@ -148,7 +148,7 @@ public override int Int32Val(int doc) // a match! return docs.Freq; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("caught exception in function " + outerInstance.GetDescription() + " : doc=" + doc, e); } diff --git a/src/Lucene.Net.QueryParser/Analyzing/AnalyzingQueryParser.cs b/src/Lucene.Net.QueryParser/Analyzing/AnalyzingQueryParser.cs index 0015996746..4857bc42cf 100644 --- a/src/Lucene.Net.QueryParser/Analyzing/AnalyzingQueryParser.cs +++ b/src/Lucene.Net.QueryParser/Analyzing/AnalyzingQueryParser.cs @@ -212,7 +212,7 @@ protected internal virtual string AnalyzeSingleChunk(string field, string termSt throw new ParseException(string.Format(@"Analyzer returned nothing for ""{0}""", chunk)); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new ParseException( string.Format(@"IO error while trying to analyze single term: ""{0}""", termStr), e); diff --git a/src/Lucene.Net.QueryParser/Classic/FastCharStream.cs b/src/Lucene.Net.QueryParser/Classic/FastCharStream.cs index 709a1602f3..e21c114d97 100644 --- a/src/Lucene.Net.QueryParser/Classic/FastCharStream.cs +++ b/src/Lucene.Net.QueryParser/Classic/FastCharStream.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using Console = Lucene.Net.Util.SystemConsole; @@ -120,7 +120,7 @@ public void Done() { input.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { Console.Error.WriteLine("Caught: " + e + "; ignoring."); } diff --git a/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs b/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs index 7d577f6701..fdba505813 100644 --- a/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs +++ b/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs @@ -614,7 +614,7 @@ protected internal virtual BytesRef AnalyzeMultitermTerm(string field, string pa source.End(); return BytesRef.DeepCopyOf(bytes); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("Error analyzing multiTerm term: " + part, e); } diff --git a/src/Lucene.Net.QueryParser/Classic/QueryParserTokenManager.cs b/src/Lucene.Net.QueryParser/Classic/QueryParserTokenManager.cs index f307bb7d91..a1b87821b8 100644 --- a/src/Lucene.Net.QueryParser/Classic/QueryParserTokenManager.cs +++ b/src/Lucene.Net.QueryParser/Classic/QueryParserTokenManager.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Support.IO; +using Lucene.Net.Support.IO; using System; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -111,7 +111,7 @@ private int JjStartNfaWithStates_2(int pos, int kind, int state) { m_curChar = m_input_stream.ReadChar(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { return pos + 1; } @@ -728,7 +728,7 @@ private int JjMoveNfa_2(int startState, int curPos) { m_curChar = m_input_stream.ReadChar(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { return curPos; } @@ -829,7 +829,7 @@ private int JjMoveNfa_0(int startState, int curPos) { m_curChar = m_input_stream.ReadChar(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { return curPos; } @@ -882,7 +882,7 @@ private int JjMoveStringLiteralDfa1_1(long active0) { m_curChar = m_input_stream.ReadChar(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { JjStopStringLiteralDfa_1(0, active0); return 1; @@ -909,7 +909,7 @@ private int JjStartNfaWithStates_1(int pos, int kind, int state) { m_curChar = m_input_stream.ReadChar(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { return pos + 1; } @@ -1074,7 +1074,7 @@ private int JjMoveNfa_1(int startState, int curPos) { m_curChar = m_input_stream.ReadChar(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { return curPos; } @@ -1252,7 +1252,7 @@ public virtual Token GetNextToken() { m_curChar = m_input_stream.BeginToken(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { jjmatchedKind = 0; matchedToken = JjFillToken(); @@ -1306,7 +1306,7 @@ public virtual Token GetNextToken() { m_input_stream.ReadChar(); m_input_stream.BackUp(1); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { EOFSeen = true; error_after = curPos <= 1?"":m_input_stream.Image; diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/FastCharStream.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/FastCharStream.cs index 46da7ecea4..85fef748da 100644 --- a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/FastCharStream.cs +++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/FastCharStream.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; namespace Lucene.Net.QueryParsers.Flexible.Standard.Parser { @@ -118,7 +119,7 @@ public void Done() { input.Dispose(); } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception e) when (e.IsIOException()) { // ignore } diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserTokenManager.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserTokenManager.cs index 1b73994a95..57646672fc 100644 --- a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserTokenManager.cs +++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserTokenManager.cs @@ -1,5 +1,6 @@ using Lucene.Net.Support.IO; using System.Diagnostics.CodeAnalysis; +using System; using System.IO; using Console = Lucene.Net.Util.SystemConsole; @@ -88,9 +89,7 @@ private int JjMoveStringLiteralDfa0_2() private int JjMoveStringLiteralDfa1_2(long active0) { try { m_curChar = m_input_stream.ReadChar(); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { JjStopStringLiteralDfa_2(0, active0); return 1; @@ -429,9 +428,7 @@ private int JjMoveNfa_2(int startState, int curPos) if ((i = jjnewStateCnt) == (startsAt = 33 - (jjnewStateCnt = startsAt))) return curPos; try { m_curChar = m_input_stream.ReadChar(); } -#pragma warning disable 168 - catch (IOException e) { return curPos; } -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { return curPos; } } } private int JjMoveStringLiteralDfa0_0() @@ -517,9 +514,7 @@ private int JjMoveNfa_0(int startState, int curPos) if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt))) return curPos; try { m_curChar = m_input_stream.ReadChar(); } -#pragma warning disable 168 - catch (IOException e) { return curPos; } -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { return curPos; } } } private int JjStopStringLiteralDfa_1(int pos, long active0) @@ -558,9 +553,7 @@ private int JjMoveStringLiteralDfa0_1() private int JjMoveStringLiteralDfa1_1(long active0) { try { m_curChar = m_input_stream.ReadChar(); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { JjStopStringLiteralDfa_1(0, active0); return 1; @@ -581,9 +574,7 @@ private int JjStartNfaWithStates_1(int pos, int kind, int state) jjmatchedKind = kind; jjmatchedPos = pos; try { m_curChar = m_input_stream.ReadChar(); } -#pragma warning disable 168 - catch (IOException e) { return pos + 1; } -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { return pos + 1; } return JjMoveNfa_1(state, pos + 1); } private int JjMoveNfa_1(int startState, int curPos) @@ -724,9 +715,7 @@ private int JjMoveNfa_1(int startState, int curPos) if ((i = jjnewStateCnt) == (startsAt = 7 - (jjnewStateCnt = startsAt))) return curPos; try { m_curChar = m_input_stream.ReadChar(); } -#pragma warning disable 168 - catch (IOException e) { return curPos; } -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { return curPos; } } } internal static readonly int[] jjnextStates = { @@ -887,9 +876,7 @@ public virtual Token GetNextToken() { m_curChar = m_input_stream.BeginToken(); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { jjmatchedKind = 0; matchedToken = JjFillToken(); @@ -937,9 +924,7 @@ public virtual Token GetNextToken() string error_after = null; bool EOFSeen = false; try { m_input_stream.ReadChar(); m_input_stream.BackUp(1); } -#pragma warning disable 168 - catch (IOException e1) -#pragma warning restore 168 + catch (Exception e1) when (e1.IsIOException()) { EOFSeen = true; error_after = curPos <= 1 ? "" : m_input_stream.GetImage(); diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/AnalyzerQueryNodeProcessor.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/AnalyzerQueryNodeProcessor.cs index 2579e3e1be..b45aef1a52 100644 --- a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/AnalyzerQueryNodeProcessor.cs +++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/AnalyzerQueryNodeProcessor.cs @@ -144,14 +144,12 @@ protected override IQueryNode PostProcessNode(IQueryNode node) } } } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // ignore } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -185,7 +183,7 @@ protected override IQueryNode PostProcessNode(IQueryNode node) if (Debugging.AssertsEnabled) Debugging.Assert(hasNext == true); term = termAtt.ToString(); } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -214,7 +212,7 @@ protected override IQueryNode PostProcessNode(IQueryNode node) if (Debugging.AssertsEnabled) Debugging.Assert(hasNext == true); term = termAtt.ToString(); } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -239,7 +237,7 @@ protected override IQueryNode PostProcessNode(IQueryNode node) if (Debugging.AssertsEnabled) Debugging.Assert(hasNext == true); term = termAtt.ToString(); } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -308,7 +306,7 @@ protected override IQueryNode PostProcessNode(IQueryNode node) positionIncrement = posIncrAtt.PositionIncrement; } } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -379,7 +377,7 @@ protected override IQueryNode PostProcessNode(IQueryNode node) positionIncrement = posIncrAtt.PositionIncrement; } } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } diff --git a/src/Lucene.Net.QueryParser/Surround/Parser/FastCharStream.cs b/src/Lucene.Net.QueryParser/Surround/Parser/FastCharStream.cs index b4a2eb671c..16573922e0 100644 --- a/src/Lucene.Net.QueryParser/Surround/Parser/FastCharStream.cs +++ b/src/Lucene.Net.QueryParser/Surround/Parser/FastCharStream.cs @@ -120,7 +120,7 @@ public void Done() { input.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { Console.Error.WriteLine("Caught: " + e + "; ignoring."); } diff --git a/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserTokenManager.cs b/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserTokenManager.cs index af7fea8b6c..164fc8dbb2 100644 --- a/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserTokenManager.cs +++ b/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserTokenManager.cs @@ -1,4 +1,5 @@ using Lucene.Net.Support.IO; +using System; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -432,7 +433,7 @@ private int JjMoveNfa_1(int startState, int curPos) if ((i = jjnewStateCnt) == (startsAt = 38 - (jjnewStateCnt = startsAt))) return curPos; try { m_curChar = m_input_stream.ReadChar(); } - catch (IOException /*e*/) { return curPos; } + catch (Exception e) when (e.IsIOException()) { return curPos; } } } @@ -519,7 +520,7 @@ private int JjMoveNfa_0(int startState, int curPos) if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt))) return curPos; try { m_curChar = m_input_stream.ReadChar(); } - catch (IOException /*e*/) { return curPos; } + catch (Exception e) when (e.IsIOException()) { return curPos; } } } internal static readonly int[] jjnextStates = { @@ -661,7 +662,7 @@ public virtual Token GetNextToken() { m_curChar = m_input_stream.BeginToken(); } - catch (IOException /*e*/) + catch (Exception e) when (e.IsIOException()) { jjmatchedKind = 0; matchedToken = JjFillToken(); @@ -704,7 +705,7 @@ public virtual Token GetNextToken() string error_after = null; bool EOFSeen = false; try { m_input_stream.ReadChar(); m_input_stream.BackUp(1); } - catch (IOException /*e1*/) + catch (Exception e1) when (e1.IsIOException()) { EOFSeen = true; error_after = curPos <= 1 ? "" : m_input_stream.Image; diff --git a/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs b/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs index b576373725..de2736e0cb 100644 --- a/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs +++ b/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs @@ -87,9 +87,9 @@ public virtual Query GetQuery(XmlElement e) } ts.End(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { - throw new ParserException("IoException parsing stop words list in " + throw new ParserException("IOException parsing stop words list in " + GetType().Name + ":" + ioe.Message); } finally diff --git a/src/Lucene.Net.QueryParser/Xml/Builders/SpanOrTermsBuilder.cs b/src/Lucene.Net.QueryParser/Xml/Builders/SpanOrTermsBuilder.cs index 621d7102aa..086df81589 100644 --- a/src/Lucene.Net.QueryParser/Xml/Builders/SpanOrTermsBuilder.cs +++ b/src/Lucene.Net.QueryParser/Xml/Builders/SpanOrTermsBuilder.cs @@ -3,6 +3,7 @@ using Lucene.Net.Index; using Lucene.Net.Search.Spans; using Lucene.Net.Util; +using System; using System.Collections.Generic; using System.IO; using System.Xml; @@ -63,7 +64,7 @@ public override SpanQuery GetSpanQuery(XmlElement e) soq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f); return soq; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new ParserException("IOException parsing value:" + value, ioe); } diff --git a/src/Lucene.Net.QueryParser/Xml/Builders/TermsFilterBuilder.cs b/src/Lucene.Net.QueryParser/Xml/Builders/TermsFilterBuilder.cs index 5222553722..572f4892ca 100644 --- a/src/Lucene.Net.QueryParser/Xml/Builders/TermsFilterBuilder.cs +++ b/src/Lucene.Net.QueryParser/Xml/Builders/TermsFilterBuilder.cs @@ -63,7 +63,7 @@ public virtual Filter GetFilter(XmlElement e) } ts.End(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Error constructing terms from index:" + ioe, ioe); } diff --git a/src/Lucene.Net.QueryParser/Xml/Builders/TermsQueryBuilder.cs b/src/Lucene.Net.QueryParser/Xml/Builders/TermsQueryBuilder.cs index e026f8688f..1972eac630 100644 --- a/src/Lucene.Net.QueryParser/Xml/Builders/TermsQueryBuilder.cs +++ b/src/Lucene.Net.QueryParser/Xml/Builders/TermsQueryBuilder.cs @@ -61,7 +61,7 @@ public virtual Query GetQuery(XmlElement e) } ts.End(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Error constructing terms from index:" + ioe, ioe); } diff --git a/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs b/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs index 485c752321..e12758ccbb 100644 --- a/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs +++ b/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs @@ -69,7 +69,7 @@ public override Field[] CreateIndexableFields(IShape shape) //this is a hack to avoid redundant byte array copying by byteStream.toByteArray() byteStream.WriteTo(new OutputStreamAnonymousClass(bytesRef)); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -298,7 +298,7 @@ public override object ObjectVal(int docId) { return outerInstance.binaryCodec.ReadShape(dataInput); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs index ef411a74bf..3ba5cfa457 100644 --- a/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs +++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs @@ -846,7 +846,7 @@ public override long GetSizeInBytes() } return mem; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingSuggester.cs index 01775fd06f..e038838893 100644 --- a/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingSuggester.cs +++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingSuggester.cs @@ -869,7 +869,7 @@ public override IList DoLookup(string key, IEnumerable c return results; } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs index 8f30e419fc..7e8ef0d772 100644 --- a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs +++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs @@ -490,7 +490,7 @@ public override IList DoLookup(string key, IEnumerable c { return DoLookup(key, contexts, num); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // bogus: throw new Exception(ioe.ToString(), ioe); @@ -646,7 +646,7 @@ public virtual IList DoLookup(string key, IEnumerable co { prefixOutput = LookupPrefix(fst, bytesReader, token, arc); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -721,7 +721,7 @@ public virtual IList DoLookup(string key, IEnumerable co completions = searcher.Search(); if (Debugging.AssertsEnabled) Debugging.Assert(completions.IsComplete); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net.Suggest/Suggest/DocumentValueSourceDictionary.cs b/src/Lucene.Net.Suggest/Suggest/DocumentValueSourceDictionary.cs index bcb53936c1..a7b690434b 100644 --- a/src/Lucene.Net.Suggest/Suggest/DocumentValueSourceDictionary.cs +++ b/src/Lucene.Net.Suggest/Suggest/DocumentValueSourceDictionary.cs @@ -150,7 +150,7 @@ protected internal override long GetWeight(Document doc, int docId) { currentWeightValues = outerInstance.weightsValueSource.GetValues(new Dictionary(), leaves[currentLeafIndex]); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Suggest/Suggest/FileDictionary.cs b/src/Lucene.Net.Suggest/Suggest/FileDictionary.cs index d739016f59..703f65ef3e 100644 --- a/src/Lucene.Net.Suggest/Suggest/FileDictionary.cs +++ b/src/Lucene.Net.Suggest/Suggest/FileDictionary.cs @@ -118,7 +118,7 @@ public virtual IInputEnumerator GetEntryEnumerator() { return new FileEnumerator(this); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs b/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs index 441f8b05f1..0e75d19b31 100644 --- a/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs +++ b/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs @@ -161,7 +161,7 @@ private static FST.Arc[] CacheRootArcs(FST automaton) // we want highest weights first. return rootArcs.ToArray(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -204,7 +204,7 @@ private int GetExactMatchStartingFromRootArc(int rootArcIndex, BytesRef utf8) } } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { // Should never happen, but anyway. throw new Exception(e.ToString(), e); @@ -247,7 +247,7 @@ public virtual IList DoLookup(string key, int num) return LookupSortedByWeight(keyUtf8, num, false); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { // Should never happen, but anyway. throw new Exception(e.ToString(), e); diff --git a/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs b/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs index add314c40c..9be93be046 100644 --- a/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs +++ b/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs @@ -163,7 +163,7 @@ public override IList DoLookup(string key, IEnumerable c { prefixOutput = LookupPrefix(scratch, arc); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -193,7 +193,7 @@ public override IList DoLookup(string key, IEnumerable c completions = Lucene.Net.Util.Fst.Util.ShortestPaths(fst, arc, prefixOutput, weightComparer, num, !exactFirst); if (Debugging.AssertsEnabled) Debugging.Assert(completions.IsComplete); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -254,7 +254,7 @@ public virtual object Get(string key) { result = LookupPrefix(new BytesRef(key), arc); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net.TestFramework/Analysis/CollationTestBase.cs b/src/Lucene.Net.TestFramework/Analysis/CollationTestBase.cs index f3a373bd7f..ce7fe31a9a 100644 --- a/src/Lucene.Net.TestFramework/Analysis/CollationTestBase.cs +++ b/src/Lucene.Net.TestFramework/Analysis/CollationTestBase.cs @@ -261,7 +261,7 @@ public virtual void AssertThreadSafe(Analyzer analyzer) for (int i = 0; i < numTestPoints; i++) { string term = TestUtil.RandomSimpleString(Random); - IOException priorException = null; + Exception priorException = null; // LUCENENET: No need to cast to IOExcpetion TokenStream ts = analyzer.GetTokenStream("fake", new StringReader(term)); try { @@ -275,7 +275,7 @@ public virtual void AssertThreadSafe(Analyzer analyzer) Assert.IsFalse(ts.IncrementToken()); ts.End(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { priorException = e; } @@ -319,7 +319,7 @@ public override void Run() { string term = mapping.Key; BytesRef expected = mapping.Value; - IOException priorException = null; + Exception priorException = null; // LUCENENET: No need to cast to IOExcpetion TokenStream ts = this.analyzer.GetTokenStream("fake", new StringReader(term)); try { @@ -332,7 +332,7 @@ public override void Run() Assert.IsFalse(ts.IncrementToken()); ts.End(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { priorException = e; } @@ -342,7 +342,7 @@ public override void Run() } } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene3x/TermInfosWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene3x/TermInfosWriter.cs index f5bbc1f9a9..d8457f853d 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Lucene3x/TermInfosWriter.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Lucene3x/TermInfosWriter.cs @@ -1,4 +1,4 @@ -using J2N.Text; +using J2N.Text; using Lucene.Net.Diagnostics; using Lucene.Net.Index; using Lucene.Net.Store; @@ -107,9 +107,7 @@ internal TermInfosWriter(Directory directory, string segment, FieldInfos fis, in { directory.DeleteFile(IndexFileNames.SegmentFileName(segment, "", (isIndex ? Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION : Lucene3xPostingsFormat.TERMS_EXTENSION))); } -#pragma warning disable 168, IDE0059 - catch (IOException ignored) -#pragma warning restore 168, IDE0059 + catch (Exception ignored) when (ignored.IsIOException()) { } } @@ -148,9 +146,7 @@ private void Initialize(Directory directory, string segment, FieldInfos fis, int { directory.DeleteFile(IndexFileNames.SegmentFileName(segment, "", (isIndex ? Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION : Lucene3xPostingsFormat.TERMS_EXTENSION))); } -#pragma warning disable 168, IDE0059 - catch (IOException ignored) -#pragma warning restore 168, IDE0059 + catch (Exception ignored) when (ignored.IsIOException()) { } } diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs index c0b3d9c961..2b9e01df42 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; using Lucene.Net.Index; using Lucene.Net.Store; using Lucene.Net.Util; @@ -407,7 +407,7 @@ public bool MoveNext() { EncodeValues(count); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net.TestFramework/Search/CheckHits.cs b/src/Lucene.Net.TestFramework/Search/CheckHits.cs index 939479bcd5..7e63b56ae6 100644 --- a/src/Lucene.Net.TestFramework/Search/CheckHits.cs +++ b/src/Lucene.Net.TestFramework/Search/CheckHits.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Index; +using Lucene.Net.Index; using Lucene.Net.Util; using System; using System.Collections.Generic; @@ -580,7 +580,7 @@ public virtual void Collect(int doc) { exp = s.Explain(q, doc); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("exception in hitcollector of [[" + d + "]] for #" + doc, e); } diff --git a/src/Lucene.Net.TestFramework/Search/QueryUtils.cs b/src/Lucene.Net.TestFramework/Search/QueryUtils.cs index 083db1c894..a3b2da2bd9 100644 --- a/src/Lucene.Net.TestFramework/Search/QueryUtils.cs +++ b/src/Lucene.Net.TestFramework/Search/QueryUtils.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Analysis; +using Lucene.Net.Analysis; using Lucene.Net.Diagnostics; using Lucene.Net.Documents; using Lucene.Net.Index; @@ -157,7 +157,7 @@ public static void Check(Random random, Query q1, IndexSearcher s, bool wrap) CheckEqual(s.Rewrite(q1), s.Rewrite(q2)); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -207,7 +207,7 @@ public static void Check(LuceneTestCase luceneTestCase, Random random, Query q1, CheckEqual(s.Rewrite(q1), s.Rewrite(q2)); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -285,7 +285,7 @@ private static IndexReader[] LoadEmptyReaders() // LUCENENET: Avoid static const emptyReaders[5] = MakeEmptyIndex(new Random(0), 5); emptyReaders[7] = MakeEmptyIndex(new Random(0), 7); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { throw new Exception(ex.ToString(), ex); } @@ -457,7 +457,7 @@ public virtual void Collect(int doc) throw new Exception("ERROR matching docs:" + "\n\t" + (doc != scorerDoc ? "--> " : "") + "doc=" + doc + ", scorerDoc=" + scorerDoc + "\n\t" + (!more ? "--> " : "") + "tscorer.more=" + more + "\n\t" + (scoreDiff > maxDiff ? "--> " : "") + "scorerScore=" + scorerScore + " scoreDiff=" + scoreDiff + " maxDiff=" + maxDiff + "\n\t" + (scorerDiff > maxDiff ? "--> " : "") + "scorerScore2=" + scorerScore2 + " scorerDiff=" + scorerDiff + "\n\thitCollector.Doc=" + doc + " score=" + score + "\n\t Scorer=" + scorer + "\n\t Query=" + q + " " + q.GetType().Name + "\n\t Searcher=" + s + "\n\t Order=" + sbord + "\n\t Op=" + (op == skip_op ? " skip()" : " next()")); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -605,7 +605,7 @@ public virtual void Collect(int doc) } lastDoc[0] = doc; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.TestFramework/Store/BaseDirectoryTestCase.cs b/src/Lucene.Net.TestFramework/Store/BaseDirectoryTestCase.cs index c57c601045..f86004ee3f 100644 --- a/src/Lucene.Net.TestFramework/Store/BaseDirectoryTestCase.cs +++ b/src/Lucene.Net.TestFramework/Store/BaseDirectoryTestCase.cs @@ -505,7 +505,7 @@ public virtual void TestDetectClose() // assertTrue(SlowFileExists(this.dir, fileName)); // } // } - // //catch (IOException e) + // //catch (Exception e) when (e.IsIOException()) // //{ // // throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) // //} @@ -556,7 +556,7 @@ public virtual void TestDetectClose() // // Access denied is allowed for files for which the output is still open (MockDirectoryWriter enforces // // this, for example). Since we don't synchronize with the writer thread, just ignore it. // } - // catch (IOException e) + // catch (Exception e) when (e.IsIOException()) // { // throw new IOException("Something went wrong when opening: " + file, e); // } @@ -564,7 +564,7 @@ public virtual void TestDetectClose() // } // } // } - // catch (IOException e) + // catch (Exception e) when (e.IsIOException()) // { // //throw new UncheckedIOException(e); // throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) diff --git a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs index f2444ebeb1..3c35ad92b8 100644 --- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs +++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs @@ -937,9 +937,7 @@ protected override void Dispose(bool disposing) { sis.Read(m_input, file); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // OK: likely some of the .si files were deleted } diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index 19aa466163..1a50e5617a 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -2365,6 +2365,7 @@ public static IndexSearcher NewSearcher(LuceneTestCase luceneTestCase, IndexRead { if (maybeWrap) { + // LUCENENET: Rethrow.rethrow() call not needed here because it simply rethrows an exception as itself r = MaybeWrapReader(r); } // TODO: this whole check is a coverage hack, we should move it to tests for various filterreaders. @@ -2373,6 +2374,8 @@ public static IndexSearcher NewSearcher(LuceneTestCase luceneTestCase, IndexRead { // TODO: not useful to check DirectoryReader (redundant with checkindex) // but maybe sometimes run this on the other crazy readers maybeWrapReader creates? + + // LUCENENET: Rethrow.rethrow() call not needed here because it simply rethrows an exception as itself TestUtil.CheckReader(r); } IndexSearcher ret; @@ -3353,7 +3356,7 @@ public static bool SlowFileExists(Directory dir, string fileName) //// { //// f.Create(); //// } - //// catch (IOException) + //// catch (Exception ioe) when (ioe.IsIOException()) //// { //// iterate = false; //// } @@ -3409,9 +3412,7 @@ public static DirectoryInfo CreateTempDir(string prefix) iterate = false; } } -#pragma warning disable 168, IDE0059 - catch (IOException exc) -#pragma warning restore 168, IDE0059 + catch (Exception exc) when (exc.IsIOException()) { iterate = true; } @@ -3520,18 +3521,7 @@ private static void CleanupTemporaryFiles() { TestUtil.Rm(everything); } - // LUCENENET specific: UnauthorizedAccessException doesn't subclass IOException as - // AccessDeniedException does in Java, so we need a special case for it. - catch (UnauthorizedAccessException e) - { - // Type suiteClass = RandomizedContext.Current.GetTargetType; - // if (suiteClass.IsAnnotationPresent(typeof(SuppressTempFileChecks))) - // { - Console.Error.WriteLine("WARNING: Leftover undeleted temporary files " + e.Message); - return; - // } - } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { // Type suiteClass = RandomizedContext.Current.GetTargetType; // if (suiteClass.IsAnnotationPresent(typeof(SuppressTempFileChecks))) diff --git a/src/Lucene.Net.TestFramework/Util/RemoveUponClose.cs b/src/Lucene.Net.TestFramework/Util/RemoveUponClose.cs index 37cc3f9a5e..a992b8e148 100644 --- a/src/Lucene.Net.TestFramework/Util/RemoveUponClose.cs +++ b/src/Lucene.Net.TestFramework/Util/RemoveUponClose.cs @@ -1,4 +1,4 @@ -#if TESTFRAMEWORK +#if TESTFRAMEWORK // LUCENENET NOTE: This is incomplete using System; @@ -61,7 +61,7 @@ public void Dispose() { TestUtil.Rm(file); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new IOException("Could not remove temporary location '" + file.FullName + "', created at stack trace:\n" + CreationStack, e); } diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestFactories.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestFactories.cs index 412964467f..637c031de0 100644 --- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestFactories.cs +++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestFactories.cs @@ -175,8 +175,7 @@ private static AbstractAnalysisFactory Initialize(Type factoryClazz) // LUCENENE { aware.Inform(new StringMockResourceLoader("")); } -#pragma warning disable CA1031 // Do not catch general exception types - catch (IOException) + catch (Exception ignored) when (ignored.IsIOException()) { // its ok if the right files arent available or whatever to throw this } @@ -184,7 +183,6 @@ private static AbstractAnalysisFactory Initialize(Type factoryClazz) // LUCENENE { // is this ok? I guess so } -#pragma warning restore CA1031 // Do not catch general exception types } return factory; } diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestBufferedCharFilter.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestBufferedCharFilter.cs index 171970984e..8f91f34e62 100644 --- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestBufferedCharFilter.cs +++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestBufferedCharFilter.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 // This class was sourced from the Apache Harmony project // https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/ @@ -105,9 +105,7 @@ public void Test_Close() br.Read(); fail("Read on closed stream"); } -#pragma warning disable 168 - catch (IOException x) -#pragma warning restore 168 + catch (Exception x) when (x.IsIOException()) { return; } @@ -142,9 +140,7 @@ public void Test_MarkI() fail("Failed to invalidate mark properly"); } -#pragma warning disable 168 - catch (IOException x) -#pragma warning restore 168 + catch (Exception x) when (x.IsIOException()) { // Expected } @@ -227,9 +223,7 @@ public void Test_Read() new char[] { '\u8765' }))); assertTrue("Wrong double byte character", br.Read() == '\u8765'); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { fail("Exception during read test"); } @@ -252,9 +246,8 @@ public void Test_Read() assertEquals("Wrong chars", 15, @in.Read()); // Check next byte } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { - fail("Exception during read test 2:" + e); } @@ -341,7 +334,7 @@ public void Test_ReadCII() { toRet.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { fail("unexpected 1: " + e); @@ -353,9 +346,7 @@ public void Test_ReadCII() fail("null buffer reading zero bytes on closed stream should throw IOException"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { //expected } @@ -367,9 +358,7 @@ public void Test_ReadCII() fail("Reading zero bytes on a closed reader should not work"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } @@ -386,9 +375,7 @@ public void Test_ReadCII() fail("IOException should have been thrown"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } @@ -412,7 +399,7 @@ public void Test_ReadCII() assertEquals("Reading zero bytes at EOF should work", 0, toRet .Read(ca, 0, 0)); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { fail("Unexpected IOException : " + ex.ToString()); @@ -428,9 +415,7 @@ public void Test_ReadCII() assertTrue("Chars read improperly", new string(buf, 50, 500) .Equals(testString.Substring(0, 500 - 0), StringComparison.Ordinal)); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { fail("Exception during read test"); @@ -478,7 +463,7 @@ public void Test_ReadCII() assertTrue("Incorrect result: " + result, result == 1); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { fail("Unexpected: " + e); @@ -520,9 +505,7 @@ public void Test_ReadCII() reader.Read(null, 1, 0); fail("Assert 1: IOException expected"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // Expected } @@ -534,9 +517,7 @@ public void Test_ReadCII() reader.Read(ch, 0, 42); fail("Assert 2: IOException expected"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } @@ -681,9 +662,7 @@ public void Test_Read_CII_Exception() fail("should throw IOException"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } @@ -694,9 +673,7 @@ public void Test_Read_CII_Exception() fail("should throw IOException"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } @@ -707,9 +684,7 @@ public void Test_Read_CII_Exception() fail("should throw IOException"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } @@ -728,9 +703,7 @@ public void Test_ReadLine() assertEquals("readLine returned incorrect string", "Test_All_Tests", r ); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { fail("Exception during readLine test"); } @@ -747,7 +720,7 @@ public void Test_Ready() br = new BufferedCharFilter(new StringReader(testString)); assertTrue("IsReady returned false", br.IsReady); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { fail("Exception during ready test" + e.toString()); } @@ -771,9 +744,7 @@ public void Test_Reset() assertTrue("Failed to reset properly", testString.Substring(500, 1000 - 500).Equals(new string(buf, 0, 500), StringComparison.Ordinal)); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { fail("Exception during reset test"); } @@ -784,9 +755,7 @@ public void Test_Reset() br.Reset(); fail("Reset succeeded on unmarked stream"); } -#pragma warning disable 168 - catch (IOException x) -#pragma warning restore 168 + catch (Exception x) when (x.IsIOException()) { return; @@ -810,9 +779,7 @@ public void Test_Reset_IOException() br.Reset(); fail("should throw IOException"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // Expected } @@ -850,9 +817,7 @@ public void Test_SkipJ() assertTrue("Failed to set skip properly", testString.Substring(500, 1000 - 500).Equals(new string(buf, 0, 500), StringComparison.Ordinal)); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { fail("Exception during skip test"); } diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs index fedf943c8c..dca8890459 100644 --- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs +++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using J2N; using Lucene.Net.Util; using NUnit.Framework; @@ -35,7 +35,7 @@ private void assertNotFound(IResourceLoader rl) IOUtils.DisposeWhileHandlingException(rl.OpenResource("/this-directory-really-really-really-should-not-exist/foo/bar.txt")); fail("The resource does not exist, should fail!"); } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { // pass } diff --git a/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs b/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs index 0d13094114..0d69f8bf66 100644 --- a/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs +++ b/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs @@ -51,7 +51,7 @@ public static UserDictionary ReadDict() @is.Dispose(); } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs index 96b0892b53..b3bd0585fe 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs @@ -98,7 +98,7 @@ public override void Run() { tw.AddCategory(new FacetLabel("a", cat)); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -296,7 +296,7 @@ public override void Run() { destTW.AddCategory(new FacetLabel("a", Convert.ToString(i, CultureInfo.InvariantCulture))); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { // shouldn't happen - if it does, let the test fail on uncaught exception. throw new Exception(e.ToString(), e); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index 9a2f56da8e..123c0a7b66 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -212,7 +212,7 @@ public override void Run() } iw.AddDocument(config.Build(tw, doc)); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index c6d6241541..8e0f135e1d 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -383,7 +383,7 @@ public override void Run() values[l3] = l3; values[l4] = l4; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs index f23cd738e1..26ca11a3f9 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs @@ -104,7 +104,7 @@ public override void Run() { ordsReader.GetReader(context); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs index 4071db14e2..01fac10b69 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs @@ -110,7 +110,7 @@ public override void Run() mgr.MaybeRefresh(); } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs index d56e83a75e..73918028ca 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs @@ -410,7 +410,7 @@ public override double DoubleVal(int document) { return scorer.GetScore(); } - catch (IOException exception) + catch (Exception exception) when (exception.IsIOException()) { throw new Exception(exception.ToString(), exception); } diff --git a/src/Lucene.Net.Tests.Spatial/SpatialTestCase.cs b/src/Lucene.Net.Tests.Spatial/SpatialTestCase.cs index eb6479115b..6dd8373c9d 100644 --- a/src/Lucene.Net.Tests.Spatial/SpatialTestCase.cs +++ b/src/Lucene.Net.Tests.Spatial/SpatialTestCase.cs @@ -122,7 +122,7 @@ protected virtual SearchResults executeQuery(Query query, int numDocs) } return new SearchResults(topDocs.TotalHits, results); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("IOException thrown while executing query", ioe); } diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs index 2231119b9c..7f3385dd74 100644 --- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs +++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs @@ -553,7 +553,7 @@ public override void Run() topN, allTermsRequired, doHilite); Thread.Sleep(10);// don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms } - catch (Exception e) + catch (Exception e) when (e.IsIOException()) { error[0] = e; stop.Value = true; @@ -1038,9 +1038,7 @@ public void IndexDocument(AnalyzingInfixSuggester suggester, String key) { suggester.Add(new BytesRef(key), null, 10, null); } -#pragma warning disable CS0168 // Variable is declared but never used - catch (IOException e) -#pragma warning restore CS0168 // Variable is declared but never used + catch (Exception e) when (e.IsIOException()) { fail("Could not build suggest dictionary correctly"); } diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs index e4ab707407..36b7c153be 100644 --- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs +++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs @@ -152,7 +152,7 @@ public bool MoveNext() { doc = lfd.NextDoc(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Tests.TestFramework/Store/TestMockDirectoryWrapper.cs b/src/Lucene.Net.Tests.TestFramework/Store/TestMockDirectoryWrapper.cs index 401e970b02..e3fc8d5621 100644 --- a/src/Lucene.Net.Tests.TestFramework/Store/TestMockDirectoryWrapper.cs +++ b/src/Lucene.Net.Tests.TestFramework/Store/TestMockDirectoryWrapper.cs @@ -102,7 +102,7 @@ public void TestDiskFull() fail("should have failed on disk full"); } #pragma warning disable 168 - catch (IOException e) + catch (Exception e) #pragma warning restore 168 { // expected @@ -128,7 +128,7 @@ public void TestDiskFull() fail("should have failed on disk full"); } #pragma warning disable 168 - catch (IOException e) + catch (Exception e) #pragma warning restore 168 { // expected diff --git a/src/Lucene.Net.Tests/Index/TestBinaryDocValuesUpdates.cs b/src/Lucene.Net.Tests/Index/TestBinaryDocValuesUpdates.cs index 6148f47e17..ae40bb8040 100644 --- a/src/Lucene.Net.Tests/Index/TestBinaryDocValuesUpdates.cs +++ b/src/Lucene.Net.Tests/Index/TestBinaryDocValuesUpdates.cs @@ -1385,7 +1385,7 @@ public override void Run() // System.out.println("[" + Thread.currentThread().getName() + "] DONE"); success = true; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1397,7 +1397,7 @@ public override void Run() { reader.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (success) // suppress this exception only if there was another exception { diff --git a/src/Lucene.Net.Tests/Index/TestCodecHoldsOpenFiles.cs b/src/Lucene.Net.Tests/Index/TestCodecHoldsOpenFiles.cs index e24a8a72f1..05238df6e9 100644 --- a/src/Lucene.Net.Tests/Index/TestCodecHoldsOpenFiles.cs +++ b/src/Lucene.Net.Tests/Index/TestCodecHoldsOpenFiles.cs @@ -1,6 +1,7 @@ -using Lucene.Net.Attributes; +using Lucene.Net.Attributes; using Lucene.Net.Documents; using NUnit.Framework; +using System; using System.IO; namespace Lucene.Net.Index @@ -57,9 +58,7 @@ public virtual void Test() { d.DeleteFile(fileName); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // ignore: this means codec (correctly) is holding // the file open @@ -102,9 +101,7 @@ public virtual void TestExposeUnclosedFiles() { d.DeleteFile(fileName); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // ignore: this means codec (correctly) is holding // the file open diff --git a/src/Lucene.Net.Tests/Index/TestCompoundFile.cs b/src/Lucene.Net.Tests/Index/TestCompoundFile.cs index b56f0ae2bf..4682b55c90 100644 --- a/src/Lucene.Net.Tests/Index/TestCompoundFile.cs +++ b/src/Lucene.Net.Tests/Index/TestCompoundFile.cs @@ -336,9 +336,7 @@ private void Demo_FSIndexInputBug(Directory fsdir, string file) @in.ReadByte(); Assert.Fail("expected readByte() to throw exception"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected exception } @@ -568,9 +566,7 @@ public virtual void TestFileNotFound() cr.OpenInput("bogus", NewIOContext(Random)); Assert.Fail("File not found"); } -#pragma warning disable 168 - catch (Exception e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { /* success */ //System.out.println("SUCCESS: File Not Found: " + e); @@ -594,9 +590,7 @@ public virtual void TestReadPastEOF() @is.ReadByte(); Assert.Fail("Single byte read past end of file"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { /* success */ //System.out.println("SUCCESS: single byte read past end of file: " + e); @@ -608,9 +602,7 @@ public virtual void TestReadPastEOF() @is.ReadBytes(b, 0, 50); Assert.Fail("Block read past end of file"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { /* success */ //System.out.println("SUCCESS: block read past end of file: " + e); diff --git a/src/Lucene.Net.Tests/Index/TestConcurrentMergeScheduler.cs b/src/Lucene.Net.Tests/Index/TestConcurrentMergeScheduler.cs index 8ce1fe4000..a380751042 100644 --- a/src/Lucene.Net.Tests/Index/TestConcurrentMergeScheduler.cs +++ b/src/Lucene.Net.Tests/Index/TestConcurrentMergeScheduler.cs @@ -130,7 +130,7 @@ public virtual void TestFlushExceptions() } extraCount++; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { if (Verbose) { diff --git a/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs b/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs index 9db32e1eb9..ef4ba89014 100644 --- a/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs +++ b/src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Documents; +using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; using NUnit.Framework; using System; @@ -333,9 +333,7 @@ public virtual void TestExpirationTimeDeletionPolicy() Assert.IsTrue(lastDeleteTime - modTime <= leeway, "commit point was older than " + SECONDS + " seconds (" + (lastDeleteTime - modTime) + " msec) but did not get deleted "); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // OK break; @@ -645,7 +643,7 @@ public virtual void TestKeepLastNDeletionPolicy() Assert.Fail("should have failed on commits prior to last " + N); } } - catch (IOException /*e*/) + catch (Exception e) when (e.IsIOException()) { if (i != N) { @@ -765,7 +763,7 @@ public virtual void TestKeepLastNDeletionPolicyWithCreates() Assert.Fail("should have failed on commits before last " + N); } } - catch (IOException /*e*/) + catch (Exception e) when (e.IsIOException()) { if (i != N) { diff --git a/src/Lucene.Net.Tests/Index/TestDocValuesWithThreads.cs b/src/Lucene.Net.Tests/Index/TestDocValuesWithThreads.cs index 225957bf43..baf89c6ab3 100644 --- a/src/Lucene.Net.Tests/Index/TestDocValuesWithThreads.cs +++ b/src/Lucene.Net.Tests/Index/TestDocValuesWithThreads.cs @@ -293,7 +293,7 @@ public override void Run() docIDToID = sr.GetNumericDocValues("id"); Assert.IsNotNull(stringDVDirect); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net.Tests/Index/TestFieldsReader.cs b/src/Lucene.Net.Tests/Index/TestFieldsReader.cs index c798d676f8..55ae5723a3 100644 --- a/src/Lucene.Net.Tests/Index/TestFieldsReader.cs +++ b/src/Lucene.Net.Tests/Index/TestFieldsReader.cs @@ -220,9 +220,7 @@ public override object Clone() { i.Seek(GetFilePointer()); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -260,9 +258,7 @@ public virtual void TestExceptions() { reader.Document(i); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // expected exc = true; @@ -271,9 +267,7 @@ public virtual void TestExceptions() { reader.Document(i); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // expected exc = true; diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs index 7c53e7239e..6870b95a79 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs @@ -1385,7 +1385,7 @@ public override void Run() { // ignore } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } @@ -1417,7 +1417,7 @@ public override void Run() { IOUtils.Dispose(dir); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1425,7 +1425,7 @@ public override void Run() { IOUtils.Dispose(adder); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1948,7 +1948,7 @@ public StringSplitTokenizer(TextReader r) { SetReader(r); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.Message, e); } @@ -2726,7 +2726,7 @@ public virtual void TestCorruptFirstCommit() Assert.Fail("expected exception"); } } - catch (IOException /*ioe*/) + catch (Exception ioe) when (ioe.IsIOException()) { // OpenMode_e.APPEND should throw an exception since no // index exists: diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterDelete.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterDelete.cs index abefcb8600..74995e255f 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterDelete.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterDelete.cs @@ -593,7 +593,7 @@ private void DoTestOperationsOnDiskFull(bool updates) long diskUsage = startDir.GetSizeInBytes(); long diskFree = diskUsage + 10; - IOException err = null; + Exception err = null; // LUCENENET: No need to cast to IOExcpetion bool done = false; @@ -709,7 +709,7 @@ private void DoTestOperationsOnDiskFull(bool updates) done = true; } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (Verbose) { @@ -760,7 +760,7 @@ private void DoTestOperationsOnDiskFull(bool updates) { newReader = DirectoryReader.Open(dir); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); @@ -773,7 +773,7 @@ private void DoTestOperationsOnDiskFull(bool updates) { hits = searcher.Search(new TermQuery(searchTerm), null, 1000).ScoreDocs; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); @@ -919,9 +919,7 @@ public virtual void TestErrorAfterApplyDeletes() } modifier.Commit(); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // expected failed = true; @@ -1042,7 +1040,7 @@ public virtual void TestErrorInDocsWriterAdd() { modifier.AddDocument(doc); } - catch (IOException io) + catch (Exception io) when (io.IsIOException()) { if (Verbose) { diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs index 8760933210..66fc6d5290 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs @@ -240,7 +240,7 @@ public override void Run() { TestUtil.CheckIndex(writer.Directory); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { Console.WriteLine(Thread.CurrentThread.Name + ": unexpected exception1"); Console.WriteLine(ioe.StackTrace); @@ -531,9 +531,7 @@ public virtual void TestExceptionJustBeforeFlush() w.AddDocument(crashDoc, analyzer); Assert.Fail("did not hit expected exception"); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // expected } @@ -734,9 +732,7 @@ public virtual void TestDocumentsWriterAbort() { writer.AddDocument(doc); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // only one flush should fail: Assert.IsFalse(hitError); @@ -786,7 +782,7 @@ public virtual void TestDocumentsWriterExceptions() writer.AddDocument(doc); Assert.Fail("did not hit expected exception"); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { if (Verbose) { @@ -977,9 +973,7 @@ public override void Run() writer.AddDocument(doc); Assert.Fail("did not hit expected exception"); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { } @@ -1066,9 +1060,7 @@ public virtual void TestExceptionDuringSync() { writer.Commit(); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // expected } @@ -1146,9 +1138,7 @@ public virtual void TestExceptionsDuringCommit() w.Dispose(); Assert.Fail(); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { Assert.Fail("expected only RuntimeException"); } @@ -1199,7 +1189,7 @@ public virtual void TestForceMergeExceptions() { w.ForceMerge(1); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { if (ioe.InnerException == null) { @@ -1335,7 +1325,7 @@ public virtual void TestSegmentsChecksumError() { reader = DirectoryReader.Open(dir); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { Console.WriteLine(e.StackTrace); Assert.Fail("segmentInfos failed to retry fallback to correct segments_N file"); @@ -1675,7 +1665,7 @@ public virtual void TestAddDocsNonAbortingException() // BUG: CrashingFilter didn't Assert.Fail("did not hit expected exception"); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // expected Assert.AreEqual(CRASH_FAIL_MESSAGE, ioe.Message); @@ -1769,7 +1759,7 @@ public virtual void TestUpdateDocsNonAbortingException() // BUG: CrashingFilter didn't Assert.Fail("did not hit expected exception"); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // expected Assert.AreEqual(CRASH_FAIL_MESSAGE, ioe.Message); @@ -2243,7 +2233,7 @@ public virtual void TestNoLostDeletesOrUpdates() w = null; } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // FakeIOException can be thrown from mergeMiddle, in which case IW // registers it before our CMS gets to suppress it. IW.forceMerge later diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterNRTIsCurrent.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterNRTIsCurrent.cs index 2ac3b17449..1485ae86ee 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterNRTIsCurrent.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterNRTIsCurrent.cs @@ -170,9 +170,7 @@ public override void Run() { currentReader.DecRef(); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { } } @@ -239,7 +237,7 @@ public override void Run() { reader.DecRef(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (failed == null) { diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterOnDiskFull.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterOnDiskFull.cs index cbe0089fa9..cf272fe6cc 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterOnDiskFull.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterOnDiskFull.cs @@ -98,7 +98,7 @@ public virtual void TestAddDocumentOnDiskFull() } writer.Commit(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (Verbose) { @@ -128,7 +128,7 @@ public virtual void TestAddDocumentOnDiskFull() } writer.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (Verbose) { @@ -299,7 +299,7 @@ public virtual void TestAddIndexOnDiskFull() // Make a new dir that will enforce disk usage: MockDirectoryWrapper dir = new MockDirectoryWrapper(Random, new RAMDirectory(startDir, NewIOContext(Random))); indWriter = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.APPEND).SetMergePolicy(NewLogMergePolicy(false))); - IOException err = null; + Exception err = null; // LUCENENET: No need to cast to IOExcpetion IMergeScheduler ms = indWriter.Config.MergeScheduler; for (int x = 0; x < 2; x++) @@ -420,7 +420,7 @@ public virtual void TestAddIndexOnDiskFull() done = true; } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { success = false; err = e; @@ -455,7 +455,7 @@ public virtual void TestAddIndexOnDiskFull() { reader = DirectoryReader.Open(dir); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { Console.WriteLine(e.StackTrace); Assert.Fail(testName + ": exception when creating IndexReader: " + e); @@ -484,7 +484,7 @@ public virtual void TestAddIndexOnDiskFull() { hits = searcher.Search(new TermQuery(searchTerm), null, END_COUNT).ScoreDocs; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { Console.WriteLine(e.StackTrace); Assert.Fail(testName + ": exception when searching: " + e); @@ -618,9 +618,7 @@ public virtual void TestCorruptionAfterDiskFullDuringMerge() w.Commit(); Assert.Fail("fake disk full IOExceptions not hit"); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // expected Assert.IsTrue(ftdm.didFail1 || ftdm.didFail2); @@ -653,7 +651,7 @@ public virtual void TestImmediateDiskFull() writer.AddDocument(doc); Assert.Fail("did not hit disk full"); } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { } // Without fix for LUCENE-1130: this call will hang: @@ -662,7 +660,7 @@ public virtual void TestImmediateDiskFull() writer.AddDocument(doc); Assert.Fail("did not hit disk full"); } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { } try @@ -670,7 +668,7 @@ public virtual void TestImmediateDiskFull() writer.Dispose(false); Assert.Fail("did not hit disk full"); } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { } diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterOnJRECrash.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterOnJRECrash.cs index fbcec4263f..b2b7692475 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterOnJRECrash.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterOnJRECrash.cs @@ -190,7 +190,7 @@ // } // } // } -// catch (IOException e) +// catch (Exception e) when (e.IsIOException()) // { // Console.Error.WriteLine("Couldn't pipe from the forked process: " + e.ToString()); // } diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterOutOfFileDescriptors.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterOutOfFileDescriptors.cs index 441a468131..b63f871b71 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterOutOfFileDescriptors.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterOutOfFileDescriptors.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using NUnit.Framework; @@ -141,7 +141,7 @@ public virtual void Test() Console.WriteLine("TEST: iter=" + iter + ": success"); } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { if (Verbose) { diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterWithThreads.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterWithThreads.cs index 1ea4949ad2..4585ec54a9 100644 --- a/src/Lucene.Net.Tests/Index/TestIndexWriterWithThreads.cs +++ b/src/Lucene.Net.Tests/Index/TestIndexWriterWithThreads.cs @@ -105,7 +105,7 @@ public override void Run() writer.UpdateDocument(new Term("id", "" + (idUpto++)), doc); addCount++; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { if (Verbose) { @@ -349,7 +349,7 @@ public virtual void TestMultipleThreadsFailure(Failure failure) writer.Dispose(false); success = true; } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { failure.ClearDoFail(); writer.Dispose(false); @@ -406,7 +406,7 @@ public virtual void TestSingleThreadFailure(Failure failure) writer.Commit(); Assert.Fail("did not hit exception"); } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { } failure.ClearDoFail(); diff --git a/src/Lucene.Net.Tests/Index/TestLongPostings.cs b/src/Lucene.Net.Tests/Index/TestLongPostings.cs index 4ffecfa943..17bf323dac 100644 --- a/src/Lucene.Net.Tests/Index/TestLongPostings.cs +++ b/src/Lucene.Net.Tests/Index/TestLongPostings.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Analysis.TokenAttributes; +using Lucene.Net.Analysis.TokenAttributes; using Lucene.Net.Diagnostics; using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; @@ -58,7 +58,7 @@ private string GetRandomTerm(string other) { continue; } - IOException priorException = null; + Exception priorException = null; // LUCENENET: No need to cast to IOExcpetion TokenStream ts = a.GetTokenStream("foo", new StringReader(s)); try { @@ -88,7 +88,7 @@ private string GetRandomTerm(string other) return s; } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { priorException = e; } diff --git a/src/Lucene.Net.Tests/Index/TestMixedDocValuesUpdates.cs b/src/Lucene.Net.Tests/Index/TestMixedDocValuesUpdates.cs index 61a7417eda..0cdab1fee6 100644 --- a/src/Lucene.Net.Tests/Index/TestMixedDocValuesUpdates.cs +++ b/src/Lucene.Net.Tests/Index/TestMixedDocValuesUpdates.cs @@ -1,4 +1,4 @@ -using J2N.Threading; +using J2N.Threading; using J2N.Threading.Atomic; using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; @@ -424,7 +424,7 @@ public override void Run() // System.out.println("[" + Thread.currentThread().getName() + "] DONE"); success = true; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -436,7 +436,7 @@ public override void Run() { reader.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (success) // suppress this exception only if there was another exception { diff --git a/src/Lucene.Net.Tests/Index/TestNumericDocValuesUpdates.cs b/src/Lucene.Net.Tests/Index/TestNumericDocValuesUpdates.cs index afd0ffc288..32338ba9cd 100644 --- a/src/Lucene.Net.Tests/Index/TestNumericDocValuesUpdates.cs +++ b/src/Lucene.Net.Tests/Index/TestNumericDocValuesUpdates.cs @@ -1,4 +1,4 @@ -using J2N.Threading; +using J2N.Threading; using J2N.Threading.Atomic; using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; @@ -1299,7 +1299,7 @@ public override void Run() // System.out.println("[" + Thread.currentThread().getName() + "] DONE"); success = true; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1311,7 +1311,7 @@ public override void Run() { reader.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (success) // suppress this exception only if there was another exception { diff --git a/src/Lucene.Net.Tests/Index/TestPersistentSnapshotDeletionPolicy.cs b/src/Lucene.Net.Tests/Index/TestPersistentSnapshotDeletionPolicy.cs index 14e8a67b08..210f8d96f6 100644 --- a/src/Lucene.Net.Tests/Index/TestPersistentSnapshotDeletionPolicy.cs +++ b/src/Lucene.Net.Tests/Index/TestPersistentSnapshotDeletionPolicy.cs @@ -136,7 +136,7 @@ public virtual void TestExceptionDuringSave() { psdp.Snapshot(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { if (ioe.Message.Equals("now fail on purpose", StringComparison.Ordinal)) { diff --git a/src/Lucene.Net.Tests/Index/TestSegmentReader.cs b/src/Lucene.Net.Tests/Index/TestSegmentReader.cs index df9019cf67..04c9483f4d 100644 --- a/src/Lucene.Net.Tests/Index/TestSegmentReader.cs +++ b/src/Lucene.Net.Tests/Index/TestSegmentReader.cs @@ -1,4 +1,4 @@ -using NUnit.Framework; +using NUnit.Framework; using System; using System.Collections.Generic; using Assert = Lucene.Net.TestFramework.Assert; @@ -177,7 +177,7 @@ public virtual void TestNorms() byte [] norms = reader.norms(DocHelper.TEXT_FIELD_1_KEY); System.out.println("Norms: " + norms); Assert.IsTrue(norms != null); - } catch (IOException e) { + } catch (Exception e) when (e.IsIOException()) { e.printStackTrace(); Assert.IsTrue(false); } diff --git a/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs b/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs index ea9e81a9b7..cef2a7268b 100644 --- a/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs +++ b/src/Lucene.Net.Tests/Index/TestTermVectorsWriter.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Documents; +using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; using NUnit.Framework; using System; @@ -192,7 +192,7 @@ public virtual void TestEndOffsetPositionWithCachingTokenFilter() Analyzer analyzer = new MockAnalyzer(Random); IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer)); Document doc = new Document(); - IOException priorException = null; + Exception priorException = null; // LUCENENET: No need to cast to IOExcpetion TokenStream stream = analyzer.GetTokenStream("field", new StringReader("abcd ")); try { @@ -207,7 +207,7 @@ public virtual void TestEndOffsetPositionWithCachingTokenFilter() doc.Add(f); w.AddDocument(doc); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { priorException = e; } diff --git a/src/Lucene.Net.Tests/Index/TestTransactions.cs b/src/Lucene.Net.Tests/Index/TestTransactions.cs index 2db2705ddf..bc744c02db 100644 --- a/src/Lucene.Net.Tests/Index/TestTransactions.cs +++ b/src/Lucene.Net.Tests/Index/TestTransactions.cs @@ -246,7 +246,7 @@ public override void DoWork() r1 = DirectoryReader.Open(dir1); r2 = DirectoryReader.Open(dir2); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (!e.Message.Contains("on purpose")) { diff --git a/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs b/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs index fbeb1120b8..ea4be552f5 100644 --- a/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs +++ b/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs @@ -87,7 +87,7 @@ public virtual void Test() TestTermPositionVectors(reader, i); } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { Assert.Fail(ioe.Message); } @@ -101,7 +101,7 @@ public virtual void Test() /// close the opened reader reader.Dispose(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { Console.WriteLine(ioe.ToString()); Console.Write(ioe.StackTrace); diff --git a/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs b/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs index 9a4b9f93f4..61a9c05e10 100644 --- a/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs +++ b/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Analysis; +using Lucene.Net.Analysis; using Lucene.Net.Analysis.TokenAttributes; using Lucene.Net.Documents; using Lucene.Net.Index; @@ -788,7 +788,7 @@ public virtual void TestRandomPhrases() break; } } - IOException priorException = null; + Exception priorException = null; // LUCENENET: No need to cast to IOExcpetion TokenStream ts = analyzer.GetTokenStream("ignore", new StringReader(term)); try { @@ -802,7 +802,7 @@ public virtual void TestRandomPhrases() } ts.End(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { priorException = e; } diff --git a/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs b/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs index 6d1a4d0550..b806f6c20d 100644 --- a/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs +++ b/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Documents; +using Lucene.Net.Documents; using Lucene.Net.Support; using NUnit.Framework; using System; @@ -396,24 +396,31 @@ public virtual void TestRandom() Array.Sort(expected, Comparer.Create((a, b) => { - int av = idToNum[Convert.ToInt32(r.Document(a).Get("id"))]; - int bv = idToNum[Convert.ToInt32(r.Document(b).Get("id"))]; - if (av < bv) + try { - return -reverseInt; - } - else if (bv < av) - { - return reverseInt; + int av = idToNum[Convert.ToInt32(r.Document(a).Get("id"))]; + int bv = idToNum[Convert.ToInt32(r.Document(b).Get("id"))]; + if (av < bv) + { + return -reverseInt; + } + else if (bv < av) + { + return reverseInt; + } + else + { + // Tie break by docID, ascending + return a - b; + } } - else + catch (Exception ioe) when (ioe.IsIOException()) { - // Tie break by docID, ascending - return a - b; + throw new RuntimeException(ioe); } }) ); - + bool fail = false; for (int i = 0; i < numHits; i++) { diff --git a/src/Lucene.Net.Tests/Search/TestSortRescorer.cs b/src/Lucene.Net.Tests/Search/TestSortRescorer.cs index a053b804a4..987c422921 100644 --- a/src/Lucene.Net.Tests/Search/TestSortRescorer.cs +++ b/src/Lucene.Net.Tests/Search/TestSortRescorer.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Documents; +using Lucene.Net.Documents; using NUnit.Framework; using System; using System.Collections.Generic; @@ -169,20 +169,27 @@ public virtual void TestRandom() Array.Sort(expected, Comparer.Create((a, b) => { - int av = idToNum[Convert.ToInt32(r.Document(a).Get("id"))]; - int bv = idToNum[Convert.ToInt32(r.Document(b).Get("id"))]; - if (av < bv) + try { - return -reverseInt; + int av = idToNum[Convert.ToInt32(r.Document(a).Get("id"))]; + int bv = idToNum[Convert.ToInt32(r.Document(b).Get("id"))]; + if (av < bv) + { + return -reverseInt; + } + else if (bv < av) + { + return reverseInt; + } + else + { + // Tie break by docID, ascending + return a - b; + } } - else if (bv < av) + catch (Exception ioe) when (ioe.IsIOException()) { - return reverseInt; - } - else - { - // Tie break by docID, ascending - return a - b; + throw new RuntimeException(ioe); } })); diff --git a/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs b/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs index 188ad4b88c..c54bb2c0ee 100644 --- a/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs +++ b/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Documents; +using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; using NUnit.Framework; using System; @@ -178,9 +178,7 @@ public virtual void TestEOF() CheckReadBytes(input, 11, pos); Assert.Fail("Block read past end of file"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { /* success */ } @@ -190,9 +188,7 @@ public virtual void TestEOF() CheckReadBytes(input, 50, pos); Assert.Fail("Block read past end of file"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { /* success */ } @@ -202,9 +198,7 @@ public virtual void TestEOF() CheckReadBytes(input, 100000, pos); Assert.Fail("Block read past end of file"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { /* success */ } diff --git a/src/Lucene.Net.Tests/Store/TestCopyBytes.cs b/src/Lucene.Net.Tests/Store/TestCopyBytes.cs index 541b951dd8..fab5794031 100644 --- a/src/Lucene.Net.Tests/Store/TestCopyBytes.cs +++ b/src/Lucene.Net.Tests/Store/TestCopyBytes.cs @@ -1,4 +1,4 @@ -using J2N.Threading; +using J2N.Threading; using NUnit.Framework; using System; using System.IO; @@ -191,7 +191,7 @@ public override void Run() dst.CopyBytes(src, src.Length - 100); dst.Dispose(); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { throw new Exception(ex.ToString(), ex); } diff --git a/src/Lucene.Net.Tests/Store/TestDirectory.cs b/src/Lucene.Net.Tests/Store/TestDirectory.cs index 4d1913e5cd..7fc3e11f71 100644 --- a/src/Lucene.Net.Tests/Store/TestDirectory.cs +++ b/src/Lucene.Net.Tests/Store/TestDirectory.cs @@ -109,7 +109,7 @@ public override void Run() using (IndexOutput output = outerBDWrapper.CreateOutput(fileName, NewIOContext(Random))) { } Assert.IsTrue(SlowFileExists(outerBDWrapper, fileName)); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -151,7 +151,7 @@ public override void Run() catch (DirectoryNotFoundException) { } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (!e.Message.Contains("still open for writing")) { @@ -164,7 +164,7 @@ public override void Run() } } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Tests/Store/TestLock.cs b/src/Lucene.Net.Tests/Store/TestLock.cs index 74e26e8deb..d00075fd1b 100644 --- a/src/Lucene.Net.Tests/Store/TestLock.cs +++ b/src/Lucene.Net.Tests/Store/TestLock.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using NUnit.Framework; +using System; using System.IO; using Assert = Lucene.Net.TestFramework.Assert; @@ -37,9 +38,7 @@ public virtual void TestObtain() @lock.Obtain(Lock.LOCK_POLL_INTERVAL); Assert.Fail("Should have failed to obtain lock"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { Assert.AreEqual(@lock.LockAttempts, 2, "should attempt to lock more than once"); } diff --git a/src/Lucene.Net.Tests/Store/TestLockFactory.cs b/src/Lucene.Net.Tests/Store/TestLockFactory.cs index 7858295a28..e3e0e22026 100644 --- a/src/Lucene.Net.Tests/Store/TestLockFactory.cs +++ b/src/Lucene.Net.Tests/Store/TestLockFactory.cs @@ -129,9 +129,7 @@ public virtual void TestDefaultRAMDirectory() writer2 = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).SetOpenMode(OpenMode.APPEND)); Assert.Fail("Should have hit an IOException with two IndexWriters on default SingleInstanceLockFactory"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { } @@ -313,7 +311,7 @@ public override void Run() { writer = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).SetOpenMode(OpenMode.APPEND)); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (e.ToString().IndexOf(" timed out:", StringComparison.Ordinal) == -1) { @@ -344,7 +342,7 @@ public override void Run() { outerInstance.AddDoc(writer); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { HitException = true; Console.WriteLine("Stress Test Index Writer: addDoc hit unexpected exception: " + e.ToString()); @@ -355,7 +353,7 @@ public override void Run() { writer.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { HitException = true; Console.WriteLine("Stress Test Index Writer: close hit unexpected exception: " + e.ToString()); @@ -410,7 +408,7 @@ public override void Run() { searcher.Search(query, null, 1000); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { HitException = true; Console.WriteLine("Stress Test Index Searcher: search hit unexpected exception: " + e.ToString()); @@ -422,7 +420,7 @@ public override void Run() { reader.Dispose(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { HitException = true; Console.WriteLine("Stress Test Index Searcher: close hit unexpected exception: " + e.ToString()); diff --git a/src/Lucene.Net.Tests/Store/TestMockDirectoryWrapper.cs b/src/Lucene.Net.Tests/Store/TestMockDirectoryWrapper.cs index 22e2e4aa65..7735dc40f5 100644 --- a/src/Lucene.Net.Tests/Store/TestMockDirectoryWrapper.cs +++ b/src/Lucene.Net.Tests/Store/TestMockDirectoryWrapper.cs @@ -83,9 +83,7 @@ public void TestDiskFull() @out.WriteBytes(bytes, bytes.Length); Assert.Fail("should have failed on disk full"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } @@ -105,9 +103,7 @@ public void TestDiskFull() @out.CopyBytes(new ByteArrayDataInput(bytes), bytes.Length); Assert.Fail("should have failed on disk full"); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // expected } diff --git a/src/Lucene.Net.Tests/Store/TestRAMDirectory.cs b/src/Lucene.Net.Tests/Store/TestRAMDirectory.cs index 76970da7f9..848802991d 100644 --- a/src/Lucene.Net.Tests/Store/TestRAMDirectory.cs +++ b/src/Lucene.Net.Tests/Store/TestRAMDirectory.cs @@ -1,4 +1,4 @@ -using J2N.Threading; +using J2N.Threading; using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; using NUnit.Framework; @@ -165,7 +165,7 @@ public override void Run() { writer.AddDocument(doc); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs index 2393db418a..3206b557b9 100644 --- a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs +++ b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs @@ -1376,9 +1376,7 @@ public virtual void TestBlockPackedReaderWriter() it.Next(); Assert.IsTrue(false); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // OK } @@ -1415,9 +1413,7 @@ public virtual void TestBlockPackedReaderWriter() it2.Skip(1); Assert.IsTrue(false); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { // OK } diff --git a/src/Lucene.Net.Tests/Util/TestIOUtils.cs b/src/Lucene.Net.Tests/Util/TestIOUtils.cs index 9e85de9e5a..bc8ae8621e 100644 --- a/src/Lucene.Net.Tests/Util/TestIOUtils.cs +++ b/src/Lucene.Net.Tests/Util/TestIOUtils.cs @@ -1,4 +1,4 @@ -using NUnit.Framework; +using NUnit.Framework; using System; using System.IO; using Assert = Lucene.Net.TestFramework.Assert; @@ -64,11 +64,9 @@ public virtual void TestSuppressedExceptions() assertEquals("TEST-IO-EXCEPTION-1", e1.GetSuppressed()[0].Message); assertEquals("TEST-IO-EXCEPTION-2", e1.GetSuppressed()[1].Message); } -#pragma warning disable 168 - catch (Exception e2) -#pragma warning restore 168 + catch (Exception e2) when (e2.IsIOException()) { - Assert.Fail("Exception should not be thrown here"); + Assert.Fail("IOException should not be thrown here"); } // test without prior exception @@ -82,7 +80,7 @@ public virtual void TestSuppressedExceptions() { fail("TestException should not be thrown here"); } - catch (IOException e2) + catch (Exception e2) when (e2.IsIOException()) { assertEquals("TEST-IO-EXCEPTION-1", e2.Message); assertEquals(1, e2.GetSuppressed().Length); diff --git a/src/Lucene.Net/Codecs/BlockTreeTermsWriter.cs b/src/Lucene.Net/Codecs/BlockTreeTermsWriter.cs index e7d4bcf1fd..af20c3fa69 100644 --- a/src/Lucene.Net/Codecs/BlockTreeTermsWriter.cs +++ b/src/Lucene.Net/Codecs/BlockTreeTermsWriter.cs @@ -1283,7 +1283,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - IOException ioe = null; + Exception ioe = null; // LUCENENET: No need to cast to IOExcpetion try { long dirStart = @out.GetFilePointer(); @@ -1312,7 +1312,7 @@ protected override void Dispose(bool disposing) WriteIndexTrailer(indexOut, indexDirStart); CodecUtil.WriteFooter(indexOut); } - catch (IOException ioe2) + catch (Exception ioe2) when (ioe2.IsIOException()) { ioe = ioe2; } diff --git a/src/Lucene.Net/Codecs/Lucene42/Lucene42DocValuesProducer.cs b/src/Lucene.Net/Codecs/Lucene42/Lucene42DocValuesProducer.cs index 5b4e24be73..e97e9ab55f 100644 --- a/src/Lucene.Net/Codecs/Lucene42/Lucene42DocValuesProducer.cs +++ b/src/Lucene.Net/Codecs/Lucene42/Lucene42DocValuesProducer.cs @@ -1,4 +1,4 @@ -using J2N.Threading.Atomic; +using J2N.Threading.Atomic; using Lucene.Net.Index; using Lucene.Net.Util.Fst; using System; @@ -486,7 +486,7 @@ public override void LookupOrd(int ord, BytesRef result) result.Length = 0; Util.ToBytesRef(output, result); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -510,7 +510,7 @@ public override int LookupTerm(BytesRef key) return (int)-o.Output.GetValueOrDefault() - 1; } } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -620,7 +620,7 @@ public override void LookupOrd(long ord, BytesRef result) result.Length = 0; Lucene.Net.Util.Fst.Util.ToBytesRef(output, result); } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -644,7 +644,7 @@ public override long LookupTerm(BytesRef key) return -o.Output.GetValueOrDefault() - 1; } } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } diff --git a/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs b/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs index 2f4fb0a238..77e1e28e43 100644 --- a/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs +++ b/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs @@ -491,7 +491,7 @@ public override void Get(long id, BytesRef result) result.Offset = 0; result.Length = buffer.Length; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -559,7 +559,7 @@ public override void Get(long id, BytesRef result) result.Offset = 0; result.Length = length; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -843,7 +843,7 @@ public virtual bool Get(int index) @in.Seek(offset + (index >> 3)); return (@in.ReadByte() & (1 << (index & 7))) != 0; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1023,7 +1023,7 @@ public override void Get(long id, BytesRef result) result.Offset = term.Offset; result.Length = term.Length; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1047,7 +1047,7 @@ internal virtual long LookupTerm(BytesRef key) return -termsEnum.Ord - 1; } } - catch (IOException bogus) + catch (Exception bogus) when (bogus.IsIOException()) { throw new Exception(bogus.ToString(), bogus); } @@ -1060,7 +1060,7 @@ internal virtual TermsEnum GetTermsEnum() { return GetTermsEnum((IndexInput)data.Clone()); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net/Index/BinaryDocValuesWriter.cs b/src/Lucene.Net/Index/BinaryDocValuesWriter.cs index f519501f4f..48fff4af76 100644 --- a/src/Lucene.Net/Index/BinaryDocValuesWriter.cs +++ b/src/Lucene.Net/Index/BinaryDocValuesWriter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; @@ -96,7 +96,7 @@ public virtual void AddValue(int docID, BytesRef value) { bytesOut.WriteBytes(value.Bytes, value.Offset, value.Length); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // Should never happen! throw new Exception(ioe.ToString(), ioe); @@ -158,7 +158,7 @@ private IEnumerable GetBytesIterator(int maxDocParam) { bytesIterator.ReadBytes(value.Bytes, value.Offset, value.Length); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { // Should never happen! throw new Exception(ioe.ToString(), ioe); diff --git a/src/Lucene.Net/Index/DocTermOrds.cs b/src/Lucene.Net/Index/DocTermOrds.cs index 891f5928ff..55d8990037 100644 --- a/src/Lucene.Net/Index/DocTermOrds.cs +++ b/src/Lucene.Net/Index/DocTermOrds.cs @@ -1068,7 +1068,7 @@ public override void LookupOrd(long ord, BytesRef result) { @ref = outerInstance.LookupTerm(te, (int)ord); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1092,7 +1092,7 @@ public override long LookupTerm(BytesRef key) return -te.Ord - 1; } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -1104,9 +1104,7 @@ public override TermsEnum GetTermsEnum() { return outerInstance.GetOrdTermsEnum(reader); } -#pragma warning disable 168 - catch (IOException e) -#pragma warning restore 168 + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net/Index/IndexFileDeleter.cs b/src/Lucene.Net/Index/IndexFileDeleter.cs index fd52c455cf..d2376d9c05 100644 --- a/src/Lucene.Net/Index/IndexFileDeleter.cs +++ b/src/Lucene.Net/Index/IndexFileDeleter.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; using Lucene.Net.Support; using System; using System.Collections.Generic; @@ -232,7 +232,7 @@ public IndexFileDeleter(Directory directory, IndexDeletionPolicy policy, Segment } sis = null; } - catch (IOException /*e*/) + catch (Exception e) when (e.IsIOException()) { if (SegmentInfos.GenerationFromSegmentsFileName(fileName) <= currentGen && directory.FileLength(fileName) > 0) { @@ -280,7 +280,7 @@ public IndexFileDeleter(Directory directory, IndexDeletionPolicy policy, Segment { sis.Read(directory, currentSegmentsFile); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new CorruptIndexException("failed to locate current segments_N file \"" + currentSegmentsFile + "\"" + e.ToString(), e); } @@ -715,7 +715,7 @@ internal void DeleteFile(string fileName) } directory.DeleteFile(fileName); } // if delete fails - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { // Some operating systems (e.g. Windows) don't // permit a file to be deleted while it is opened diff --git a/src/Lucene.Net/Index/IndexWriter.cs b/src/Lucene.Net/Index/IndexWriter.cs index ca465486af..19e9283c8e 100644 --- a/src/Lucene.Net/Index/IndexWriter.cs +++ b/src/Lucene.Net/Index/IndexWriter.cs @@ -848,7 +848,7 @@ public IndexWriter(Directory d, IndexWriterConfig conf) segmentInfos.Read(directory); segmentInfos.Clear(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { // Likely this means it's a fresh directory initialIndexExists = false; @@ -5090,7 +5090,7 @@ private int MergeMiddle(MergePolicy.OneMerge merge) filesToRemove = CreateCompoundFile(infoStream, directory, checkAbort, merge.info.Info, context); success = true; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { lock (this) { @@ -5685,7 +5685,8 @@ internal static ICollection CreateCompoundFile(InfoStream infoStream, Di // Now merge all added files ICollection files = info.GetFiles(); CompoundFileDirectory cfsDir = new CompoundFileDirectory(directory, fileName, context, true); - IOException prior = null; + // LUCENENET: Ported changes to this method from 4.8.1 + bool success = false; try { foreach (string file in files) @@ -5693,37 +5694,30 @@ internal static ICollection CreateCompoundFile(InfoStream infoStream, Di directory.Copy(cfsDir, file, file, context); checkAbort.Work(directory.FileLength(file)); } - } - catch (IOException ex) - { - prior = ex; + success = true; } finally { - bool success = false; - try + if (success) { - IOUtils.DisposeWhileHandlingException(prior, cfsDir); - success = true; + IOUtils.Dispose(cfsDir); } - finally + else { - if (!success) + IOUtils.DisposeWhileHandlingException(cfsDir); + try + { + directory.DeleteFile(fileName); + } + catch (Exception t) when (t.IsThrowable()) + { + } + try + { + directory.DeleteFile(Lucene.Net.Index.IndexFileNames.SegmentFileName(info.Name, "", Lucene.Net.Index.IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION)); + } + catch (Exception t) when (t.IsThrowable()) { - try - { - directory.DeleteFile(fileName); - } - catch (Exception t) when (t.IsThrowable()) - { - } - try - { - directory.DeleteFile(Lucene.Net.Index.IndexFileNames.SegmentFileName(info.Name, "", Lucene.Net.Index.IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION)); - } - catch (Exception t) when (t.IsThrowable()) - { - } } } } diff --git a/src/Lucene.Net/Index/MultiReader.cs b/src/Lucene.Net/Index/MultiReader.cs index c0a1e32eda..2ed3e6a584 100644 --- a/src/Lucene.Net/Index/MultiReader.cs +++ b/src/Lucene.Net/Index/MultiReader.cs @@ -1,3 +1,4 @@ +using System; using System.IO; namespace Lucene.Net.Index @@ -73,7 +74,7 @@ protected internal override void DoClose() { lock (this) { - IOException ioe = null; + Exception ioe = null; // LUCENENET: No need to cast to IOExcpetion foreach (IndexReader r in GetSequentialSubReaders()) { try @@ -87,7 +88,7 @@ protected internal override void DoClose() r.DecRef(); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (ioe == null) { diff --git a/src/Lucene.Net/Index/ParallelAtomicReader.cs b/src/Lucene.Net/Index/ParallelAtomicReader.cs index 354e113075..6dc912b7c0 100644 --- a/src/Lucene.Net/Index/ParallelAtomicReader.cs +++ b/src/Lucene.Net/Index/ParallelAtomicReader.cs @@ -1,4 +1,4 @@ -using J2N.Runtime.CompilerServices; +using J2N.Runtime.CompilerServices; using Lucene.Net.Support; using System; using System.Collections.Generic; @@ -285,7 +285,7 @@ protected internal override void DoClose() { lock (this) { - IOException ioe = null; + Exception ioe = null; // LUCENENET: No need to cast to IOExcpetion foreach (AtomicReader reader in completeReaderSet) { try @@ -299,7 +299,7 @@ protected internal override void DoClose() reader.DecRef(); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (ioe == null) { diff --git a/src/Lucene.Net/Index/ParallelCompositeReader.cs b/src/Lucene.Net/Index/ParallelCompositeReader.cs index 1bc75e2516..c61a6c1d21 100644 --- a/src/Lucene.Net/Index/ParallelCompositeReader.cs +++ b/src/Lucene.Net/Index/ParallelCompositeReader.cs @@ -1,4 +1,4 @@ -using J2N.Runtime.CompilerServices; +using J2N.Runtime.CompilerServices; using Lucene.Net.Diagnostics; using Lucene.Net.Support; using System; @@ -223,7 +223,7 @@ protected internal override void DoClose() { lock (this) { - IOException ioe = null; + Exception ioe = null; // LUCENENET: No need to cast to IOExcpetion foreach (IndexReader reader in completeReaderSet) { try @@ -237,7 +237,7 @@ protected internal override void DoClose() reader.DecRef(); } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (ioe == null) { diff --git a/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs b/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs index 1915ed16df..a568901a03 100644 --- a/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs +++ b/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs @@ -245,9 +245,7 @@ internal void Persist() { dir.DeleteFile(lastSaveFile); } -#pragma warning disable 168 - catch (IOException ioe) -#pragma warning restore 168 + catch (Exception ioe) when (ioe.IsIOException()) { // OK: likely it didn't exist } @@ -301,7 +299,7 @@ private void LoadPriorSnapshots() lock (this) { long genLoaded = -1; - IOException ioe = null; + Exception ioe = null; // LUCENENET: No need to cast to IOExcpetion IList snapshotFiles = new List(); foreach (string file in dir.ListAll()) { @@ -324,7 +322,7 @@ private void LoadPriorSnapshots() m[commitGen] = refCount; } } - catch (IOException ioe2) + catch (Exception ioe2) when (ioe2.IsIOException()) { // Save first exception & throw in the end if (ioe == null) diff --git a/src/Lucene.Net/Index/PrefixCodedTerms.cs b/src/Lucene.Net/Index/PrefixCodedTerms.cs index 0b9deee14e..4556be7398 100644 --- a/src/Lucene.Net/Index/PrefixCodedTerms.cs +++ b/src/Lucene.Net/Index/PrefixCodedTerms.cs @@ -1,4 +1,4 @@ -using J2N.Numerics; +using J2N.Numerics; using Lucene.Net.Diagnostics; using System; using System.Collections; @@ -76,7 +76,7 @@ internal PrefixCodedTermsIterator(RAMFile buffer) { input = new RAMInputStream("PrefixCodedTermsIterator", buffer); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -121,7 +121,7 @@ public virtual bool MoveNext() bytes.Length = prefix + suffix; term.Set(field, bytes); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -174,7 +174,7 @@ public virtual void Add(Term term) lastTerm.Bytes.CopyBytes(term.Bytes); lastTerm.Field = term.Field; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -189,7 +189,7 @@ public virtual PrefixCodedTerms Finish() output.Dispose(); return new PrefixCodedTerms(buffer); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } diff --git a/src/Lucene.Net/Index/SegmentInfos.cs b/src/Lucene.Net/Index/SegmentInfos.cs index 5ba0f73ba3..4e075d078a 100644 --- a/src/Lucene.Net/Index/SegmentInfos.cs +++ b/src/Lucene.Net/Index/SegmentInfos.cs @@ -628,7 +628,7 @@ private static bool SegmentWasUpgraded(Directory directory, SegmentInfo si) return true; } } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { // Ignore: if something is wrong w/ the marker file, // we will just upgrade again @@ -827,7 +827,7 @@ public virtual object Run(IndexCommit commit) long lastGen = -1; long gen = 0; int genLookaheadCount = 0; - IOException exc = null; + Exception exc = null; // LUCENENET: No need to cast to IOExcpetion int retryCount = 0; bool useFirstMethod = true; @@ -882,7 +882,7 @@ public virtual object Run(IndexCommit commit) { genInput = directory.OpenChecksumInput(IndexFileNames.SEGMENTS_GEN, IOContext.READ_ONCE); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { if (infoStream != null) { @@ -924,7 +924,7 @@ public virtual object Run(IndexCommit commit) throw new IndexFormatTooNewException(genInput, version, FORMAT_SEGMENTS_GEN_START, FORMAT_SEGMENTS_GEN_CURRENT); } } - catch (IOException err2) + catch (Exception err2) when (err2.IsIOException()) { // rethrow any format exception if (err2 is CorruptIndexException) @@ -1007,7 +1007,7 @@ public virtual object Run(IndexCommit commit) } return v; } - catch (IOException err) + catch (Exception err) when (err.IsIOException()) { // Save the original root cause: if (exc == null) @@ -1036,7 +1036,7 @@ public virtual object Run(IndexCommit commit) directory.OpenInput(prevSegmentFileName, IOContext.DEFAULT).Dispose(); prevExists = true; } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception ioe) when (ioe.IsIOException()) { prevExists = false; } @@ -1056,7 +1056,7 @@ public virtual object Run(IndexCommit commit) } return v; } - catch (IOException err2) + catch (Exception err2) when (err2.IsIOException()) { if (infoStream != null) { diff --git a/src/Lucene.Net/Index/StandardDirectoryReader.cs b/src/Lucene.Net/Index/StandardDirectoryReader.cs index 137d2b3aa6..8c3f43d4be 100644 --- a/src/Lucene.Net/Index/StandardDirectoryReader.cs +++ b/src/Lucene.Net/Index/StandardDirectoryReader.cs @@ -68,24 +68,21 @@ protected internal override object DoBody(string segmentFileName) var sis = new SegmentInfos(); sis.Read(directory, segmentFileName); var readers = new SegmentReader[sis.Count]; + // LUCENENET: Ported over changes from 4.8.1 to this method for (int i = sis.Count - 1; i >= 0; i--) { - IOException prior = null; + //IOException prior = null; // LUCENENET: Not used bool success = false; try { readers[i] = new SegmentReader(sis.Info(i), termInfosIndexDivisor, IOContext.READ); success = true; } - catch (IOException ex) - { - prior = ex; - } finally { if (!success) { - IOUtils.DisposeWhileHandlingException(prior, readers); + IOUtils.DisposeWhileHandlingException(readers); } } } diff --git a/src/Lucene.Net/Index/TieredMergePolicy.cs b/src/Lucene.Net/Index/TieredMergePolicy.cs index 1524d9fc38..fd9dce5576 100644 --- a/src/Lucene.Net/Index/TieredMergePolicy.cs +++ b/src/Lucene.Net/Index/TieredMergePolicy.cs @@ -1,4 +1,4 @@ -using J2N.Text; +using J2N.Text; using Lucene.Net.Support; using System; using System.Collections.Generic; @@ -271,7 +271,7 @@ public virtual int Compare(SegmentCommitInfo o1, SegmentCommitInfo o2) return o1.Info.Name.CompareToOrdinal(o2.Info.Name); } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net/Search/ControlledRealTimeReopenThread.cs b/src/Lucene.Net/Search/ControlledRealTimeReopenThread.cs index 690846f393..8cdb40ae9a 100644 --- a/src/Lucene.Net/Search/ControlledRealTimeReopenThread.cs +++ b/src/Lucene.Net/Search/ControlledRealTimeReopenThread.cs @@ -263,7 +263,7 @@ public override void Run() { manager.MaybeRefreshBlocking(); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception(ioe.ToString(), ioe); } diff --git a/src/Lucene.Net/Store/ByteBufferIndexInput.cs b/src/Lucene.Net/Store/ByteBufferIndexInput.cs index e1381df838..31b8a557b5 100644 --- a/src/Lucene.Net/Store/ByteBufferIndexInput.cs +++ b/src/Lucene.Net/Store/ByteBufferIndexInput.cs @@ -257,7 +257,7 @@ public override sealed object Clone() { clone.Seek(GetFilePointer()); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Should never happen: " + this, ioe); } @@ -280,7 +280,7 @@ public ByteBufferIndexInput Slice(string sliceDescription, long offset, long len { clone.Seek(0L); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new Exception("Should never happen: " + this, ioe); } diff --git a/src/Lucene.Net/Store/CompoundFileDirectory.cs b/src/Lucene.Net/Store/CompoundFileDirectory.cs index c887250090..2d22c5cc25 100644 --- a/src/Lucene.Net/Store/CompoundFileDirectory.cs +++ b/src/Lucene.Net/Store/CompoundFileDirectory.cs @@ -1,4 +1,4 @@ -using J2N.Collections.Generic.Extensions; +using J2N.Collections.Generic.Extensions; using J2N.Numerics; using Lucene.Net.Diagnostics; using Lucene.Net.Support; @@ -140,7 +140,7 @@ public CompoundFileDirectory(Directory directory, string fileName, IOContext con /// Helper method that reads CFS entries from an input stream private static IDictionary ReadEntries(IndexInputSlicer handle, Directory dir, string name) { - IOException priorE = null; + Exception priorE = null; // LUCENENET: No need to cast to IOExcpetion IndexInput stream = null; ChecksumIndexInput entriesStream = null; // read the first VInt. If it is negative, it's the version number @@ -201,7 +201,7 @@ private static IDictionary ReadEntries(IndexInputSlicer handl } return mapping; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { priorE = ioe; } diff --git a/src/Lucene.Net/Store/CompoundFileWriter.cs b/src/Lucene.Net/Store/CompoundFileWriter.cs index 69023aa47f..e101aa0789 100644 --- a/src/Lucene.Net/Store/CompoundFileWriter.cs +++ b/src/Lucene.Net/Store/CompoundFileWriter.cs @@ -1,4 +1,4 @@ -using J2N.Collections.Generic.Extensions; +using J2N.Collections.Generic.Extensions; using J2N.Threading.Atomic; using Lucene.Net.Diagnostics; using System; @@ -142,7 +142,7 @@ public void Dispose() { return; } - IOException priorException = null; + Exception priorException = null; // LUCENENET: No need to cast to IOExcpetion IndexOutput entryTableOut = null; // TODO this code should clean up after itself // (remove partial .cfs/.cfe) @@ -158,7 +158,7 @@ public void Dispose() if (Debugging.AssertsEnabled) Debugging.Assert(dataOut != null); CodecUtil.WriteFooter(dataOut); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { priorException = e; } @@ -171,7 +171,7 @@ public void Dispose() entryTableOut = directory.CreateOutput(entryTableName, IOContext.DEFAULT); WriteEntryTable(entries.Values, entryTableOut); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { priorException = e; } diff --git a/src/Lucene.Net/Store/Directory.cs b/src/Lucene.Net/Store/Directory.cs index e3398916c2..6bfc59364a 100644 --- a/src/Lucene.Net/Store/Directory.cs +++ b/src/Lucene.Net/Store/Directory.cs @@ -195,14 +195,14 @@ public virtual void Copy(Directory to, string src, string dest, IOContext contex { IndexOutput os = null; IndexInput @is = null; - IOException priorException = null; + Exception priorException = null; // LUCENENET: No need to cast to IOExcpetion try { os = to.CreateOutput(dest, context); @is = OpenInput(src, context); os.CopyBytes(@is, @is.Length); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { priorException = ioe; } diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs index 8b03dd8549..6eb888353e 100644 --- a/src/Lucene.Net/Store/FSDirectory.cs +++ b/src/Lucene.Net/Store/FSDirectory.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Support; +using Lucene.Net.Support; using Lucene.Net.Support.IO; using System; using System.Collections.Generic; @@ -408,7 +408,7 @@ public override string GetLockID() { dirName = m_directory.GetCanonicalPath(); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception(e.ToString(), e); } @@ -545,12 +545,12 @@ protected override void Dispose(bool disposing) // only close the file if it has not been closed yet if (isOpen) { - IOException priorE = null; + Exception priorE = null; // LUCENENET: No need to cast to IOExcpetion try { file.Flush(flushToDisk: true); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { priorE = ioe; } diff --git a/src/Lucene.Net/Store/NIOFSDirectory.cs b/src/Lucene.Net/Store/NIOFSDirectory.cs index 12487b2e3c..b2dab685b4 100644 --- a/src/Lucene.Net/Store/NIOFSDirectory.cs +++ b/src/Lucene.Net/Store/NIOFSDirectory.cs @@ -1,4 +1,4 @@ -using J2N.IO; +using J2N.IO; using Lucene.Net.Diagnostics; using Lucene.Net.Support.IO; using System; @@ -150,7 +150,7 @@ public override IndexInput OpenFullSlice() { return OpenSlice("full-slice", 0, descriptor.Length); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { throw new Exception(ex.ToString(), ex); } @@ -271,7 +271,7 @@ protected override void ReadInternal(byte[] b, int offset, int len) } if (Debugging.AssertsEnabled) Debugging.Assert(readLength == 0); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new IOException(ioe.ToString() + ": " + this, ioe); } diff --git a/src/Lucene.Net/Store/NRTCachingDirectory.cs b/src/Lucene.Net/Store/NRTCachingDirectory.cs index f8bf8ed841..8530a843e9 100644 --- a/src/Lucene.Net/Store/NRTCachingDirectory.cs +++ b/src/Lucene.Net/Store/NRTCachingDirectory.cs @@ -1,4 +1,4 @@ -using J2N.Collections.Generic.Extensions; +using J2N.Collections.Generic.Extensions; using System; using System.Collections.Generic; using System.IO; @@ -231,7 +231,7 @@ public override IndexOutput CreateOutput(string name, IOContext context) { @delegate.DeleteFile(name); } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception ioe) when (ioe.IsIOException()) { // this is fine: file may not exist } @@ -243,7 +243,7 @@ public override IndexOutput CreateOutput(string name, IOContext context) { cache.DeleteFile(name); } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception ioe) when (ioe.IsIOException()) { // this is fine: file may not exist } diff --git a/src/Lucene.Net/Store/NativeFSLockFactory.cs b/src/Lucene.Net/Store/NativeFSLockFactory.cs index b3c59a9f78..c02efb9065 100644 --- a/src/Lucene.Net/Store/NativeFSLockFactory.cs +++ b/src/Lucene.Net/Store/NativeFSLockFactory.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Support.IO; +using Lucene.Net.Support.IO; using Lucene.Net.Util; using System; using System.IO; @@ -289,12 +289,7 @@ public override bool Obtain() success = true; } - catch (IOException e) - { - FailureReason = e; - } - // LUCENENET: UnauthorizedAccessException does not derive from IOException like in java - catch (UnauthorizedAccessException e) + catch (Exception e) when (e.IsIOException()) { // At least on OS X, we will sometimes get an // intermittent "Permission Denied" Exception, @@ -396,7 +391,7 @@ public override bool IsLocked() } return !obtained; } - catch (IOException) + catch (Exception ioe) when (ioe.IsIOException()) { return false; } @@ -483,12 +478,7 @@ public override bool Obtain() { // no failure reason to be recorded, since this is the expected error if a lock exists } - catch (IOException e) - { - FailureReason = e; - } - // LUCENENET: UnauthorizedAccessException does not derive from IOException like in java - catch (UnauthorizedAccessException e) + catch (Exception e) when (e.IsIOException()) { // At least on OS X, we will sometimes get an // intermittent "Permission Denied" Exception, @@ -635,12 +625,7 @@ public override bool Obtain() { stream = GetLockFileStream(FileMode.OpenOrCreate); } - catch (IOException e) - { - FailureReason = e; - } - // LUCENENET: UnauthorizedAccessException does not derive from IOException like in java - catch (UnauthorizedAccessException e) + catch (Exception e) when (e.IsIOException()) { // At least on OS X, we will sometimes get an // intermittent "Permission Denied" Exception, diff --git a/src/Lucene.Net/Store/RAMDirectory.cs b/src/Lucene.Net/Store/RAMDirectory.cs index 446ed9dea9..f9daf8a900 100644 --- a/src/Lucene.Net/Store/RAMDirectory.cs +++ b/src/Lucene.Net/Store/RAMDirectory.cs @@ -1,4 +1,4 @@ -using J2N.Collections.Generic.Extensions; +using J2N.Collections.Generic.Extensions; using J2N.Threading.Atomic; using System; using System.Collections.Concurrent; @@ -59,7 +59,7 @@ public RAMDirectory() { SetLockFactory(new SingleInstanceLockFactory()); } - catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment + catch (Exception e) when (e.IsIOException()) { // Cannot happen } diff --git a/src/Lucene.Net/Store/SimpleFSDirectory.cs b/src/Lucene.Net/Store/SimpleFSDirectory.cs index 6f94a3a288..5b58babafd 100644 --- a/src/Lucene.Net/Store/SimpleFSDirectory.cs +++ b/src/Lucene.Net/Store/SimpleFSDirectory.cs @@ -1,4 +1,4 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; using System; using System.IO; @@ -130,7 +130,7 @@ public override IndexInput OpenFullSlice() { return OpenSlice("full-slice", 0, descriptor.Length); } - catch (IOException ex) + catch (Exception ex) when (ex.IsIOException()) { throw new Exception(ex.ToString(), ex); } @@ -237,7 +237,7 @@ protected override void ReadInternal(byte[] b, int offset, int len) if (Debugging.AssertsEnabled) Debugging.Assert(total == len); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new IOException(ioe.Message + ": " + this, ioe); } diff --git a/src/Lucene.Net/Util/Automaton/RegExp.cs b/src/Lucene.Net/Util/Automaton/RegExp.cs index c3d7406aa1..ce42ad70da 100644 --- a/src/Lucene.Net/Util/Automaton/RegExp.cs +++ b/src/Lucene.Net/Util/Automaton/RegExp.cs @@ -1,4 +1,4 @@ -using J2N; +using J2N; using J2N.Text; using System; using System.Collections.Generic; @@ -616,7 +616,7 @@ private Automaton ToAutomaton(IDictionary automata, IAutomato { aa = automaton_provider.GetAutomaton(s); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new ArgumentException(e.ToString(), e); } diff --git a/src/Lucene.Net/Util/IOUtils.cs b/src/Lucene.Net/Util/IOUtils.cs index cf4a1134c5..54528ff2a0 100644 --- a/src/Lucene.Net/Util/IOUtils.cs +++ b/src/Lucene.Net/Util/IOUtils.cs @@ -564,7 +564,7 @@ public static void ReThrowUnchecked(Exception th) // file.Flush(true); // success = true; // } - // catch (IOException e) + // catch (Exception e) when (e.IsIOException()) // { // if (retryCount == 5) // { diff --git a/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs b/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs index 4c618b6590..119e6c0132 100644 --- a/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs +++ b/src/Lucene.Net/Util/Packed/DirectPacked64SingleBlockReader.cs @@ -52,7 +52,7 @@ public override long Get(int index) int offsetInBlock = index % valuesPerBlock; return (block.TripleShift(offsetInBlock * m_bitsPerValue)) & mask; } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new InvalidOperationException("failed", e); } diff --git a/src/Lucene.Net/Util/Packed/DirectPackedReader.cs b/src/Lucene.Net/Util/Packed/DirectPackedReader.cs index 754ca7c025..9077a709d8 100644 --- a/src/Lucene.Net/Util/Packed/DirectPackedReader.cs +++ b/src/Lucene.Net/Util/Packed/DirectPackedReader.cs @@ -109,7 +109,7 @@ public override long Get(int index) } return (rawValue.TripleShift(shiftRightBits)) & valueMask; } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new InvalidOperationException("failed", ioe); } diff --git a/src/Lucene.Net/Util/Packed/PackedInts.cs b/src/Lucene.Net/Util/Packed/PackedInts.cs index c2f36625d3..5bf389220e 100644 --- a/src/Lucene.Net/Util/Packed/PackedInts.cs +++ b/src/Lucene.Net/Util/Packed/PackedInts.cs @@ -1121,7 +1121,7 @@ public override long Get(int index) { @in.Seek(endPointer); } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new InvalidOperationException("failed", e); } diff --git a/src/Lucene.Net/Util/QueryBuilder.cs b/src/Lucene.Net/Util/QueryBuilder.cs index 85905b6fa5..cfe6a092d0 100644 --- a/src/Lucene.Net/Util/QueryBuilder.cs +++ b/src/Lucene.Net/Util/QueryBuilder.cs @@ -1,4 +1,4 @@ -using J2N.Collections.Generic.Extensions; +using J2N.Collections.Generic.Extensions; using Lucene.Net.Analysis.TokenAttributes; using Lucene.Net.Diagnostics; using System; @@ -237,13 +237,13 @@ protected Query CreateFieldQuery(Analyzer analyzer, Occur @operator, string fiel hasMoreTokens = buffer.IncrementToken(); } } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { // ignore } } } - catch (IOException e) + catch (Exception e) when (e.IsIOException()) { throw new Exception("Error analyzing query text", e); } @@ -269,7 +269,7 @@ protected Query CreateFieldQuery(Analyzer analyzer, Occur @operator, string fiel if (Debugging.AssertsEnabled) Debugging.Assert(hasNext == true); termAtt.FillBytesRef(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -295,7 +295,7 @@ protected Query CreateFieldQuery(Analyzer analyzer, Occur @operator, string fiel if (Debugging.AssertsEnabled) Debugging.Assert(hasNext == true); termAtt.FillBytesRef(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -317,7 +317,7 @@ protected Query CreateFieldQuery(Analyzer analyzer, Occur @operator, string fiel if (Debugging.AssertsEnabled) Debugging.Assert(hasNext == true); termAtt.FillBytesRef(); } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -364,7 +364,7 @@ protected Query CreateFieldQuery(Analyzer analyzer, Occur @operator, string fiel positionIncrement = posIncrAtt.PositionIncrement; } } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } @@ -415,7 +415,7 @@ protected Query CreateFieldQuery(Analyzer analyzer, Occur @operator, string fiel positionIncrement = posIncrAtt.PositionIncrement; } } - catch (IOException) + catch (Exception e) when (e.IsIOException()) { // safe to ignore, because we know the number of tokens } diff --git a/src/Lucene.Net/Util/SPIClassIterator.cs b/src/Lucene.Net/Util/SPIClassIterator.cs index 1829817329..abcb57c911 100644 --- a/src/Lucene.Net/Util/SPIClassIterator.cs +++ b/src/Lucene.Net/Util/SPIClassIterator.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; @@ -183,7 +183,7 @@ private SPIClassIterator(Type clazz, ClassLoader loader) string fullName = META_INF_SERVICES + clazz.Name; this.ProfilesEnum = (loader == null) ? ClassLoader.getSystemResources(fullName) : loader.getResources(fullName); } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new ServiceConfigurationError("Error loading SPI profiles for type " + clazz.Name + " from classpath", ioe); } @@ -227,7 +227,7 @@ private bool LoadNextProfile() } } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { priorE = ioe; } @@ -236,7 +236,7 @@ private bool LoadNextProfile() IOUtils.CloseWhileHandlingException(priorE, @in); } } - catch (IOException ioe) + catch (Exception ioe) when (ioe.IsIOException()) { throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe); } diff --git a/src/Lucene.Net/Util/WAH8DocIdSet.cs b/src/Lucene.Net/Util/WAH8DocIdSet.cs index b9455e247d..0b6c7ce92a 100644 --- a/src/Lucene.Net/Util/WAH8DocIdSet.cs +++ b/src/Lucene.Net/Util/WAH8DocIdSet.cs @@ -353,7 +353,7 @@ internal virtual void WriteSequence() { WriteHeader(reverse, clean, dirtyWords.Length); } - catch (IOException cannotHappen) + catch (Exception cannotHappen) when (cannotHappen.IsIOException()) { throw new InvalidOperationException(cannotHappen.ToString(), cannotHappen); // LUCENENET NOTE: This was AssertionError in Lucene }