You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/12/11 03:35:20 UTC

[GitHub] [incubator-pinot] kishoreg commented on a change in pull request #4907: Replacing usage of Class.forName with PluginManager.createInstance

kishoreg commented on a change in pull request #4907: Replacing usage of Class.forName with PluginManager.createInstance
URL: https://github.com/apache/incubator-pinot/pull/4907#discussion_r356389514
 
 

 ##########
 File path: pinot-spi/src/main/java/org/apache/pinot/spi/plugin/PluginManager.java
 ##########
 @@ -156,14 +155,18 @@ private PluginClassLoader createClassLoader(Collection<URL> urlList) {
    * @param <T>
    * @return
    */
-  public <T> T createInstance(String pluginName, String className, Class[] argTypes, Object[] argValues)
-      throws Exception {
+  public <T> T createInstance(String pluginName, String className, Class[] argTypes, Object[] argValues) throws Exception{
     PluginClassLoader pluginClassLoader = PLUGIN_MANAGER._registry.get(new Plugin(pluginName));
-    Class<T> loadedClass = (Class<T>) pluginClassLoader.loadClass(className, true);
-    Constructor<?> constructor = loadedClass.getConstructor(argTypes);
-    if (constructor != null) {
-      Object instance = constructor.newInstance(argValues);
-      return (T) instance;
+    try {
+      Class<T> loadedClass = (Class<T>) pluginClassLoader.loadClass(className, true);
+      Constructor<?> constructor = null;
+      constructor = loadedClass.getConstructor(argTypes);
+      if (constructor != null) {
+        Object instance = constructor.newInstance(argValues);
+        return (T) instance;
+      }
+    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
 
 Review comment:
   Isn't it better for the caller to log it?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org