This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 7e772c2c8a3834e4fbf122835fea8c3b3fc5a941
Author: Shad Storhaug <[email protected]>
AuthorDate: Wed Jul 31 15:23:48 2019 +0700

    BUG: Lucene.Net.TestFramework.Util.LuceneTestCase.NewFSDirectory - When 
resolving a type, we were expecting an exception if the type does not subclass 
FSDirectory, however, in .NET this won't happen. We need to explicitly check 
whether the resolved type is assignable from FSDirectory or if the type name is 
nonsense.
---
 src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs 
b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index 54d08ec..a2a2b67 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -1261,14 +1261,13 @@ namespace Lucene.Net.Util
                 fsdirClass = RandomInts.RandomFrom(Random(), FS_DIRECTORIES);
             }
 
-            Type clazz;
-            try
-            {
-                clazz = CommandLineUtil.LoadFSDirectoryClass(fsdirClass);
-            }
-#pragma warning disable 168
-            catch (System.InvalidCastException e)
-#pragma warning restore 168
+            // LUCENENET specific - .NET will not throw an exception if the
+            // class does not inherit FSDirectory. We get a null if the name
+            // cannot be resolved, not an exception.
+            // We need to do an explicit check to determine if this type
+            // is not a subclass of FSDirectory.
+            Type clazz = CommandLineUtil.LoadFSDirectoryClass(fsdirClass);
+            if (clazz == null || 
!(typeof(FSDirectory).IsAssignableFrom(clazz)))
             {
                 // TEST_DIRECTORY is not a sub-class of FSDirectory, so draw 
one at random
                 fsdirClass = RandomInts.RandomFrom(Random(), FS_DIRECTORIES);

Reply via email to