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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new dcdbc38  Only use reflection VFS.createFileSystemManager(String) if 
the FileSystemManager is not a subclass of AbstractFileSystem.
dcdbc38 is described below

commit dcdbc38eb39bd7ed56001bf72dd2abca7e660066
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Mar 14 10:12:05 2021 -0400

    Only use reflection VFS.createFileSystemManager(String) if the
    FileSystemManager is not a subclass of AbstractFileSystem.
---
 .../src/main/java/org/apache/commons/vfs2/VFS.java   | 20 ++++++++++++--------
 src/changes/changes.xml                              |  3 +++
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/VFS.java 
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/VFS.java
index 9769bb3..3fbc383 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/VFS.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/VFS.java
@@ -17,6 +17,10 @@
 package org.apache.commons.vfs2;
 
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.commons.lang3.reflect.MethodUtils;
+import org.apache.commons.vfs2.provider.AbstractFileSystem;
 
 /**
  * The main entry point for the VFS. Used to create {@link FileSystemManager} 
instances.
@@ -56,15 +60,15 @@ public final class VFS {
             // Create instance
             final Class<FileSystemManager> clazz = (Class<FileSystemManager>) 
Class.forName(managerClassName);
             final FileSystemManager manager = clazz.newInstance();
-
-            try {
-                // Initialize
-                clazz.getMethod("init", (Class[]) null).invoke(manager, 
(Object[]) null);
-            } catch (final NoSuchMethodException e) {
-                /* Ignore; don't initialize. */
-                e.printStackTrace();
+            // Initialize
+            if (manager instanceof AbstractFileSystem) {
+                ((AbstractFileSystem) manager).init();
+            } else {
+                final Method method = MethodUtils.getMatchingMethod(clazz, 
"init");
+                if (method != null) {
+                    method.invoke(manager, (Object[]) null);
+                }
             }
-
             return manager;
         } catch (final InvocationTargetException e) {
             throw new FileSystemException("vfs/create-manager.error", 
managerClassName, e.getTargetException());
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dcc9394..e30cbec 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -66,6 +66,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="update" dev="ggregory" due-to="Gary Gregory">
         Port internal embedded HTTP asynchronous file server used in tests 
from  from Apache HttpComponents HttpCore/HttpClient 4.x to 5.0.x.
       </action>
+      <action type="update" dev="ggregory" due-to="Gary Gregory">
+        Only use reflection VFS.createFileSystemManager(String) if the 
FileSystemManager is not a subclass of AbstractFileSystem.
+      </action>
     </release>
     <release version="2.8.0" date="2021-03-06" description="Feature and 
maintenance release. Requires Java 8.">
 <!--       <action issue="VFS-443" dev="ggregory" type="update" 
due-to="nickallen"> -->

Reply via email to