Github user clebertsuconic commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/2416#discussion_r233483727
  
    --- Diff: 
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl.java
 ---
    @@ -982,7 +982,13 @@ protected ConnectorFactory 
instantiateConnectorFactory(final String connectorFac
           return AccessController.doPrivileged(new 
PrivilegedAction<ConnectorFactory>() {
              @Override
              public ConnectorFactory run() {
    -            return (ConnectorFactory) 
ClassloadingUtil.newInstanceFromClassLoader(connectorFactoryClassName);
    +            ClassLoader cl = 
Thread.currentThread().getContextClassLoader();
    --- End diff --
    
    Couldn't you change ClassLoadingUtil as
    ```java
    
       public static Object newInstanceFromClassLoader(final String className) {
          return newInstanceFromClassLoader(ClassloadingUtil.class, className);
       }
    
       public static Object newInstanceFromClassLoader(Class classOwner, final 
String className) {
          ClassLoader loader = classOwner.getClassLoader();
          try {
             Class<?> clazz = loader.loadClass(className);
             return clazz.newInstance();
          } catch (Throwable t) {
             if (t instanceof InstantiationException) {
                System.out.println(INSTANTIATION_EXCEPTION_MESSAGE);
             }
             loader = Thread.currentThread().getContextClassLoader();
             if (loader == null)
                throw new RuntimeException("No local context classloader", t);
    
             try {
                return loader.loadClass(className).newInstance();
             } catch (InstantiationException e) {
                throw new RuntimeException(INSTANTIATION_EXCEPTION_MESSAGE + " 
" + className, e);
             } catch (ClassNotFoundException e) {
                throw new IllegalStateException(e);
             } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
             }
          }
       }
    ```
    
    
    and pass in the class parameter on these cases?
    
    
    Or would this have issues with Security on the JDK?
    
    
    If there are no issues I would prefer the parameter added?


---

Reply via email to