Use replacement for Class.newInstance().

It is deprecated as of Java 9, and the replacement is valid for older JVMs.
This commit is contained in:
Michael Bayne
2019-03-18 19:30:04 -07:00
parent faf94721fc
commit a2cc8ec450
7 changed files with 13 additions and 10 deletions
@@ -63,7 +63,7 @@ public class LiaisonRegistry
{
// create a new instance and stick it on our list
try {
_liaisons.add(lclass.newInstance());
_liaisons.add(lclass.getDeclaredConstructor().newInstance());
} catch (Exception e) {
log.warning("Unable to instantiate liaison", "class", lclass.getName(), "error", e);
}
@@ -243,7 +243,8 @@ public class StaticConnectionProvider implements ConnectionProvider
// create an instance of the driver
Driver jdriver;
try {
jdriver = (Driver)Class.forName(_info.driver).newInstance();
jdriver = (Driver)Class.forName(_info.driver).
getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new PersistenceException(
"Error loading driver [class=" + _info.driver + "].", e);
@@ -75,7 +75,7 @@ public class AttachableURLFactory implements URLStreamHandlerFactory
Class<? extends URLStreamHandler> handler = _handlers.get(protocol.toLowerCase());
if (handler != null) {
try {
return handler.newInstance();
return handler.getDeclaredConstructor().newInstance();
} catch (Exception e) {
log.warning("Unable to instantiate URLStreamHandler", "protocol", protocol,
"cause", e);
@@ -336,7 +336,7 @@ public class Config
public Object instantiateValue (String name, String defcname)
throws Exception
{
return Class.forName(getValue(name, defcname)).newInstance();
return Class.forName(getValue(name, defcname)).getDeclaredConstructor().newInstance();
}
/**
+1 -1
View File
@@ -199,7 +199,7 @@ public final class Log
provider = System.getProperty("log_provider");
if (provider != null) {
Class<?> lpclass = Class.forName(provider);
_provider = (LogProvider)lpclass.newInstance();
_provider = (LogProvider)lpclass.getDeclaredConstructor().newInstance();
}
} catch (SecurityException se) {
@@ -170,7 +170,8 @@ public abstract class Logger
// create and a log4j logger if the log4j configuration system property is set
try {
if (factory == null && System.getProperty("log4j.configuration") != null) {
factory = (Factory)Class.forName("com.samskivert.util.Log4JLogger").newInstance();
factory = (Factory)Class.forName("com.samskivert.util.Log4JLogger").
getDeclaredConstructor().newInstance();
}
} catch (SecurityException se) {
// in a sandbox, no biggie
@@ -181,7 +182,8 @@ public abstract class Logger
// create and a log4j2 logger if the log4j2 configuration system property is set
try {
if (factory == null && System.getProperty("log4j.configurationFile") != null) {
factory = (Factory)Class.forName("com.samskivert.util.Log4J2Logger").newInstance();
factory = (Factory)Class.forName("com.samskivert.util.Log4J2Logger").
getDeclaredConstructor().newInstance();
}
} catch (SecurityException se) {
// in a sandbox, no biggie
@@ -212,7 +214,7 @@ public abstract class Logger
}
if (!StringUtil.isBlank(implClass)) {
try {
return (Factory)Class.forName(implClass).newInstance();
return (Factory)Class.forName(implClass).getDeclaredConstructor().newInstance();
} catch (Throwable t) {
System.err.println("Unable to instantiate logging implementation: " + implClass);
t.printStackTrace(System.err);
@@ -186,7 +186,7 @@ public class DispatcherServlet extends HttpServlet
return new Application();
} else {
Class<?> appclass = Class.forName(appcl);
return (Application)appclass.newInstance();
return (Application)appclass.getDeclaredConstructor().newInstance();
}
}
@@ -597,7 +597,7 @@ public class DispatcherServlet extends HttpServlet
protected Logic instantiateLogic (String path, String lclass) {
try {
Class<?> pcl = Class.forName(lclass);
return (Logic)pcl.newInstance();
return (Logic)pcl.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException cnfe) {
// nothing interesting to report
} catch (Throwable t) {