Only use reflection VFS.createFileSystemManager(String) if the
FileSystemManager is not a subclass of AbstractFileSystem.
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 @@
// 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 @@
<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"> -->