You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/10/02 19:55:09 UTC
[commons-vfs] 01/02: Update call deprecated in Java 9
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
commit bc711eb83e92994c5ebee81219ddee38120d2aac
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Oct 2 15:54:19 2023 -0400
Update call deprecated in Java 9
DelegatingFileSystemOptionsBuilder.setConfigClass[es](FileSystemOptions,
String, String, Class<?>) now throw the more general
ReflectiveOperationException instead of 2 subclasses
---
commons-vfs2/src/main/java/org/apache/commons/vfs2/VFS.java | 2 +-
.../apache/commons/vfs2/impl/StandardFileSystemManager.java | 2 +-
.../java/org/apache/commons/vfs2/util/CryptorFactory.java | 2 +-
.../vfs2/util/DelegatingFileSystemOptionsBuilder.java | 12 +++++-------
.../test/java/org/apache/commons/vfs2/AbstractTestSuite.java | 2 +-
.../org/apache/commons/vfs2/impl/VfsClassLoaderTests.java | 4 ++--
src/changes/changes.xml | 3 +++
7 files changed, 14 insertions(+), 13 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 bd93da16..36e4e044 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
@@ -63,7 +63,7 @@ public final class VFS {
try {
// Create instance
final Class<FileSystemManager> clazz = (Class<FileSystemManager>) Class.forName(managerClassName);
- final FileSystemManager manager = clazz.newInstance();
+ final FileSystemManager manager = clazz.getConstructor().newInstance();
// Initialize
if (manager instanceof AbstractFileSystem) {
((AbstractFileSystem) manager).init();
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java
index 9c59ade7..3466e0f7 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java
@@ -254,7 +254,7 @@ public class StandardFileSystemManager extends DefaultFileSystemManager {
*/
private Object createInstance(final String className) throws FileSystemException {
try {
- return loadClass(className).newInstance();
+ return loadClass(className).getConstructor().newInstance();
} catch (final Exception e) {
throw new FileSystemException("vfs.impl/create-provider.error", className, e);
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CryptorFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CryptorFactory.java
index 0d2bd94f..533cde0f 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CryptorFactory.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CryptorFactory.java
@@ -52,7 +52,7 @@ public final class CryptorFactory {
if (cryptorClass != null) {
try {
final Class<?> clazz = Class.forName(cryptorClass);
- instance = (Cryptor) clazz.newInstance();
+ instance = (Cryptor) clazz.getConstructor().newInstance();
return instance;
} catch (final Exception ex) {
throw new IllegalStateException("Unable to create Cryptor " + cryptorClass, ex);
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java
index fb742085..ba4d3b1b 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java
@@ -283,11 +283,10 @@ public class DelegatingFileSystemOptionsBuilder {
* @param name name
* @param className className
* @throws FileSystemException if an error occurs.
- * @throws IllegalAccessException if a class cannot be accessed.
- * @throws InstantiationException if a class cannot be instantiated.
+ * @throws ReflectiveOperationException if a class cannot be accessed or instantiated.
*/
public void setConfigClass(final FileSystemOptions fso, final String scheme, final String name,
- final Class<?> className) throws FileSystemException, IllegalAccessException, InstantiationException {
+ final Class<?> className) throws FileSystemException, ReflectiveOperationException {
setConfigClasses(fso, scheme, name, new Class[] {className});
}
@@ -302,14 +301,13 @@ public class DelegatingFileSystemOptionsBuilder {
* @param name name
* @param classNames classNames
* @throws FileSystemException if an error occurs.
- * @throws IllegalAccessException if a class cannot be accessed.
- * @throws InstantiationException if a class cannot be instantiated.
+ * @throws ReflectiveOperationException if a class cannot be accessed or instantiated.
*/
public void setConfigClasses(final FileSystemOptions fso, final String scheme, final String name,
- final Class<?>[] classNames) throws FileSystemException, IllegalAccessException, InstantiationException {
+ final Class<?>[] classNames) throws FileSystemException, ReflectiveOperationException {
final Object[] values = new Object[classNames.length];
for (int iterClassNames = 0; iterClassNames < values.length; iterClassNames++) {
- values[iterClassNames] = classNames[iterClassNames].newInstance();
+ values[iterClassNames] = classNames[iterClassNames].getConstructor().newInstance();
}
final Context ctx = new Context(fso, scheme, name, values);
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java
index c068ba77..49a931ab 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java
@@ -115,7 +115,7 @@ public abstract class AbstractTestSuite extends TestSetup {
}
// Create instance
- final AbstractProviderTestCase testCase = (AbstractProviderTestCase) testClass.newInstance();
+ final AbstractProviderTestCase testCase = (AbstractProviderTestCase) testClass.getConstructor().newInstance();
testCase.setMethod(method);
testCase.setName(prefix + method.getName());
testCase.addEmptyDir(this.addEmptyDir);
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java
index cee9f8e9..57d413ca 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java
@@ -185,7 +185,7 @@ public class VfsClassLoaderTests extends AbstractProviderTestCase {
assertEquals("code", pack.getName());
verifyPackage(pack, false);
- final Object testObject = testClass.newInstance();
+ final Object testObject = testClass.getConstructor().newInstance();
assertEquals("**PRIVATE**", testObject.toString());
}
@@ -294,7 +294,7 @@ public class VfsClassLoaderTests extends AbstractProviderTestCase {
assertEquals("code", pack.getName());
verifyPackage(pack, false);
- final Object testObject = testClass.newInstance();
+ final Object testObject = testClass.getConstructor().newInstance();
assertEquals("**PRIVATE**", testObject.toString());
} catch (ReflectiveOperationException e) {
throw new IllegalStateException(e);
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ae401edb..de4072a0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -167,6 +167,9 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">
Reduce deprecated calls in org.apache.commons.vfs2.provider.http5.
</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">
+ DelegatingFileSystemOptionsBuilder.setConfigClass[es](FileSystemOptions, String, String, Class) now throw the more general ReflectiveOperationException instead of 2 subclasses.
+ </action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Seth Falco">
Add vscode files to gitignore #205.