diff --git a/src/main/java/com/amazon/redshift/core/SocketFactoryFactory.java b/src/main/java/com/amazon/redshift/core/SocketFactoryFactory.java index 37029e0..80f5e34 100644 --- a/src/main/java/com/amazon/redshift/core/SocketFactoryFactory.java +++ b/src/main/java/com/amazon/redshift/core/SocketFactoryFactory.java @@ -38,7 +38,7 @@ public static SocketFactory getSocketFactory(Properties info) throws RedshiftExc return SocketFactory.getDefault(); } try { - return (SocketFactory) ObjectFactory.instantiate(socketFactoryClassName, info, true, + return ObjectFactory.instantiate(SocketFactory.class, socketFactoryClassName, info, true, RedshiftProperty.SOCKET_FACTORY_ARG.get(info)); } catch (Exception e) { throw new RedshiftException( @@ -66,7 +66,7 @@ public static SSLSocketFactory getSslSocketFactory(Properties info) throws Redsh if (classname.equals(RedshiftConnectionImpl.NON_VALIDATING_SSL_FACTORY)) classname = NonValidatingFactory.class.getName(); - return (SSLSocketFactory) ObjectFactory.instantiate(classname, info, true, + return ObjectFactory.instantiate(SSLSocketFactory.class, classname, info, true, RedshiftProperty.SSL_FACTORY_ARG.get(info)); } catch (Exception e) { throw new RedshiftException( diff --git a/src/main/java/com/amazon/redshift/ssl/LibPQFactory.java b/src/main/java/com/amazon/redshift/ssl/LibPQFactory.java index e3dbbe0..9e7e964 100644 --- a/src/main/java/com/amazon/redshift/ssl/LibPQFactory.java +++ b/src/main/java/com/amazon/redshift/ssl/LibPQFactory.java @@ -61,7 +61,7 @@ private CallbackHandler getCallbackHandler(Properties info) throws RedshiftExcep String sslpasswordcallback = RedshiftProperty.SSL_PASSWORD_CALLBACK.get(info); if (sslpasswordcallback != null) { try { - cbh = (CallbackHandler) ObjectFactory.instantiate(sslpasswordcallback, info, false, null); + cbh = ObjectFactory.instantiate(CallbackHandler.class,sslpasswordcallback, info, false, null); } catch (Exception e) { throw new RedshiftException( GT.tr("The password callback class provided {0} could not be instantiated.", diff --git a/src/main/java/com/amazon/redshift/ssl/MakeSSL.java b/src/main/java/com/amazon/redshift/ssl/MakeSSL.java index 43042d4..cc7fef1 100644 --- a/src/main/java/com/amazon/redshift/ssl/MakeSSL.java +++ b/src/main/java/com/amazon/redshift/ssl/MakeSSL.java @@ -59,7 +59,7 @@ private static void verifyPeerName(RedshiftStream stream, Properties info, SSLSo sslhostnameverifier = "RedshiftjdbcHostnameVerifier"; } else { try { - hvn = (HostnameVerifier) instantiate(sslhostnameverifier, info, false, null); + hvn = instantiate(HostnameVerifier.class, sslhostnameverifier, info, false, null); } catch (Exception e) { throw new RedshiftException( GT.tr("The HostnameVerifier class provided {0} could not be instantiated.", diff --git a/src/main/java/com/amazon/redshift/util/ObjectFactory.java b/src/main/java/com/amazon/redshift/util/ObjectFactory.java index 4b9a5d8..663082d 100644 --- a/src/main/java/com/amazon/redshift/util/ObjectFactory.java +++ b/src/main/java/com/amazon/redshift/util/ObjectFactory.java @@ -34,13 +34,13 @@ public class ObjectFactory { * @throws IllegalAccessException if something goes wrong * @throws InvocationTargetException if something goes wrong */ - public static Object instantiate(String classname, Properties info, boolean tryString, + public static T instantiate(Class expectedClass, String classname, Properties info, boolean tryString, String stringarg) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Object[] args = {info}; - Constructor ctor = null; - Class cls = Class.forName(classname); + Constructor ctor = null; + Class cls = Class.forName(classname).asSubclass(expectedClass); try { ctor = cls.getConstructor(Properties.class); } catch (NoSuchMethodException nsme) {