ARTEMIS-5018 eliminate deprecated use of Class.newInstance
This commit is contained in:
parent
4352ebae5f
commit
465e985388
|
@ -19,6 +19,7 @@ package org.apache.activemq.artemis.utils;
|
|||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
@ -61,7 +62,11 @@ public class FactoryFinder {
|
|||
clazz = loadClass(loadProperties(path));
|
||||
classMap.put(path, clazz);
|
||||
}
|
||||
return clazz.newInstance();
|
||||
try {
|
||||
return clazz.getDeclaredConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static Class loadClass(Properties properties) throws ClassNotFoundException, IOException {
|
||||
|
|
|
@ -184,7 +184,7 @@ public final class PasswordMaskingUtil {
|
|||
// Service load the codec, if a service is available
|
||||
for (SensitiveDataCodec<String> codec : serviceLoader) {
|
||||
if (codec.getClass().getCanonicalName().equals(codecClassName)) {
|
||||
return codec.getClass().newInstance();
|
||||
return codec.getClass().getDeclaredConstructor().newInstance();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -192,11 +192,11 @@ public final class PasswordMaskingUtil {
|
|||
}
|
||||
try {
|
||||
// If a service is not available, load the codec class using this class's class loader
|
||||
return (SensitiveDataCodec<String>) PasswordMaskingUtil.class.getClassLoader().loadClass(codecClassName).newInstance();
|
||||
return (SensitiveDataCodec<String>) PasswordMaskingUtil.class.getClassLoader().loadClass(codecClassName).getDeclaredConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
// As a last resort, load the codec class using the current thread's context class loader
|
||||
return (SensitiveDataCodec<String>) Thread.currentThread().getContextClassLoader().loadClass(codecClassName).newInstance();
|
||||
return (SensitiveDataCodec<String>) Thread.currentThread().getContextClassLoader().loadClass(codecClassName).getDeclaredConstructor().newInstance();
|
||||
} catch (Exception e2) {
|
||||
throw ActiveMQUtilBundle.BUNDLE.errorCreatingCodec(codecClassName, e2);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class JNDIReferenceFactory implements ObjectFactory {
|
|||
Reference reference = (Reference) object;
|
||||
Class<?> theClass = loadClass(this, reference.getClassName());
|
||||
if (JNDIStorable.class.isAssignableFrom(theClass)) {
|
||||
JNDIStorable store = (JNDIStorable) theClass.newInstance();
|
||||
JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance();
|
||||
store.setProperties(getProperties(reference));
|
||||
result = store;
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ public final class ActiveMQRaUtils {
|
|||
try {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
Class<?> aClass = loader.loadClass(locatorClass);
|
||||
Object o = aClass.newInstance();
|
||||
Object o = aClass.getDeclaredConstructor().newInstance();
|
||||
Method m = aClass.getMethod("locateChannel", new Class[]{String.class});
|
||||
return (JChannel) m.invoke(o, name);
|
||||
} catch (Throwable e) {
|
||||
|
@ -215,12 +215,12 @@ public final class ActiveMQRaUtils {
|
|||
ClassLoader loader = getClass().getClassLoader();
|
||||
try {
|
||||
Class<?> clazz = loader.loadClass(className);
|
||||
return clazz.newInstance();
|
||||
return clazz.getDeclaredConstructor().newInstance();
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
loader = Thread.currentThread().getContextClassLoader();
|
||||
if (loader != null)
|
||||
return loader.loadClass(className).newInstance();
|
||||
return loader.loadClass(className).getDeclaredConstructor().newInstance();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ArtemisBrokerHelper {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
service = serviceClass.newInstance();
|
||||
service = serviceClass.getDeclaredConstructor().newInstance();
|
||||
Method startMethod = serviceClass.getMethod("start");
|
||||
startMethod.invoke(service, (Object[]) null);
|
||||
LOG.info("started a service instance: " + service);
|
||||
|
|
|
@ -123,8 +123,7 @@ public enum Database {
|
|||
if (driver == null) {
|
||||
String className = getDriverClass();
|
||||
ClassLoader loader = getDBClassLoader();
|
||||
Class clazz = loader.loadClass(className);
|
||||
driver = (Driver) clazz.getDeclaredConstructor().newInstance();
|
||||
driver = (Driver) loader.loadClass(className).getDeclaredConstructor().newInstance();
|
||||
}
|
||||
return driver;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public abstract class ContainerService {
|
|||
if (providerName == null) {
|
||||
loadingService = new TestContainerImpl();
|
||||
} else {
|
||||
loadingService = (ContainerService) Class.forName(providerName).newInstance();
|
||||
loadingService = (ContainerService) Class.forName(providerName).getDeclaredConstructor().newInstance();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -101,7 +101,7 @@ public class BasicXaRecoveryTest extends ActiveMQTestBase {
|
|||
super.setUp();
|
||||
|
||||
if (storeType == StoreConfiguration.StoreType.DATABASE) {
|
||||
Object unused = Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
|
||||
Object unused = Class.forName("org.apache.derby.jdbc.EmbeddedDriver").getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
addressSettings.clear();
|
||||
|
|
|
@ -71,9 +71,7 @@ public class ReferenceableTest extends JMSTestCase {
|
|||
|
||||
String factoryName = cfRef.getFactoryClassName();
|
||||
|
||||
Class<?> factoryClass = Class.forName(factoryName);
|
||||
|
||||
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
|
||||
ObjectFactory factory = (ObjectFactory) Class.forName(factoryName).getDeclaredConstructor().newInstance();
|
||||
|
||||
Object instance = factory.getObjectInstance(cfRef, null, null, null);
|
||||
|
||||
|
@ -90,9 +88,7 @@ public class ReferenceableTest extends JMSTestCase {
|
|||
|
||||
String factoryName = queueRef.getFactoryClassName();
|
||||
|
||||
Class<?> factoryClass = Class.forName(factoryName);
|
||||
|
||||
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
|
||||
ObjectFactory factory = (ObjectFactory) Class.forName(factoryName).getDeclaredConstructor().newInstance();
|
||||
|
||||
Object instance = factory.getObjectInstance(queueRef, null, null, null);
|
||||
|
||||
|
@ -111,9 +107,7 @@ public class ReferenceableTest extends JMSTestCase {
|
|||
|
||||
String factoryName = topicRef.getFactoryClassName();
|
||||
|
||||
Class factoryClass = Class.forName(factoryName);
|
||||
|
||||
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
|
||||
ObjectFactory factory = (ObjectFactory) Class.forName(factoryName).getDeclaredConstructor().newInstance();
|
||||
|
||||
Object instance = factory.getObjectInstance(topicRef, null, null, null);
|
||||
|
||||
|
|
|
@ -34,8 +34,7 @@ public class AdminFactory {
|
|||
throw new RuntimeException("Property " + AdminFactory.PROP_NAME + " has not been found in input props");
|
||||
}
|
||||
try {
|
||||
Class adminClass = Class.forName(adminClassName);
|
||||
admin = (Admin) adminClass.newInstance();
|
||||
admin = (Admin) Class.forName(adminClassName).getDeclaredConstructor().newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("Class " + adminClassName + " not found.", e);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -100,8 +100,7 @@ public class StringRefAddrReferenceTest {
|
|||
|
||||
private <T> T getObject(Reference reference, Class<T> tClass) throws Exception {
|
||||
String factoryName = reference.getFactoryClassName();
|
||||
Class<?> factoryClass = Class.forName(factoryName);
|
||||
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
|
||||
ObjectFactory factory = (ObjectFactory) Class.forName(factoryName).getDeclaredConstructor().newInstance();
|
||||
Object o = factory.getObjectInstance(reference, null, null, null);
|
||||
if (tClass.isAssignableFrom(tClass)) {
|
||||
return tClass.cast(o);
|
||||
|
|
|
@ -38,8 +38,7 @@ public class DestinationObjectFactoryTest extends ActiveMQTestBase {
|
|||
ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
|
||||
Reference reference = queue.getReference();
|
||||
String factoryName = reference.getFactoryClassName();
|
||||
Class<?> factoryClass = Class.forName(factoryName);
|
||||
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
|
||||
ObjectFactory factory = (ObjectFactory) Class.forName(factoryName).getDeclaredConstructor().newInstance();
|
||||
Object object = factory.getObjectInstance(reference, null, null, null);
|
||||
assertNotNull(object);
|
||||
assertTrue(object instanceof ActiveMQDestination);
|
||||
|
|
|
@ -129,7 +129,7 @@ public class ObjectInputStreamWithClassLoaderTest extends ActiveMQTestBase {
|
|||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||
ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais);
|
||||
|
||||
Runnable toRun = (Runnable) testClassLoader.loadClass(ProxyReader.class.getName()).newInstance();
|
||||
Runnable toRun = (Runnable) testClassLoader.loadClass(ProxyReader.class.getName()).getDeclaredConstructor().newInstance();
|
||||
toRun.getClass().getField("ois").set(toRun, ois);
|
||||
toRun.getClass().getField("testClassLoader").set(toRun, testClassLoader);
|
||||
toRun.getClass().getField("originalProxy").set(toRun, originalProxy);
|
||||
|
|
Loading…
Reference in New Issue