Uploaded image for project: 'JGroups'
  1. JGroups
  2. JGRP-1762

Util.loadClass(): do we use the correct ClassLoader ?

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major Major
    • 3.4.2, 3.5
    • None
    • None

      Investigate whether the code below uses the right classloader. Perhaps we should try to get the classloader of the instances passed to us before attempting to use the calling thread's class loader ?

      The current code is:

         public static Class loadClass(String classname, Class clazz) throws ClassNotFoundException {
              ClassLoader loader;
      
              try {
                  loader=Thread.currentThread().getContextClassLoader();
                  if(loader != null) {
                      return loader.loadClass(classname);
                  }
              }
              catch(Throwable t) {
              }
      
              if(clazz != null) {
                  try {
                      loader=clazz.getClassLoader();
                      if(loader != null) {
                          return loader.loadClass(classname);
                      }
                  }
                  catch(Throwable t) {
                  }
              }
      
              try {
                  loader=ClassLoader.getSystemClassLoader();
                  if(loader != null) {
                      return loader.loadClass(classname);
                  }
              }
              catch(Throwable t) {
              }
      
              throw new ClassNotFoundException(classname);
          }
      

              rhn-engineering-bban Bela Ban
              rhn-engineering-bban Bela Ban
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: