Figure out which ClassLoader to use.  For JDK 1.2 and later use
the context ClassLoader.
427764
static ClassLoader getClassLoader ()
    {
        Method m = null;

        try {
            m = Thread.class.getMethod("getContextClassLoader");
        } catch (NoSuchMethodException e) {
            // Assume that we are running JDK 1.1, use the current ClassLoader
            return NewInstance.class.getClassLoader();
        }

        try {
            return (ClassLoader) m.invoke(Thread.currentThread());
        } catch (IllegalAccessException e) {
            // assert(false)
            throw new UnknownError(e.getMessage());
        } catch (InvocationTargetException e) {
            // assert(e.getTargetException() instanceof SecurityException)
            throw new UnknownError(e.getMessage());
        }
    }
939405
@Override
  public Class<?> loadClassImpl(String name, boolean resolve)
    throws ClassNotFoundException
  {
    // The JVM has already cached the classes, so we don't need to
    Class<?> cl = findLoadedClass(name);

    if (cl != null) {
      if (resolve) {
        resolveClass(cl);
      }
      
      return cl;
    }

    String className = name;
    
    if (_hasBootClassPath) {
      className = name.replace('.', '/') + ".class";

      if (findPath(className) == null) {
        return null;
      }
    }

    try {
      return super.loadClassImpl(name, resolve);
    } catch (Error e) {
      className = name.replace('.', '/') + ".class";
      
      if (findPath(className) != null) {
        String msg =  (e + "\n  while loading " + name + " in " + this
                       + "\n  which exists in " + findPath(className)
                       + "\n  check for missing dependencies");
        
        log().warning(msg);
      }
      
      throw e;
    } catch (ClassNotFoundException e) {
      className = name.replace('.', '/') + ".class";
      
      if (findPath(className) != null) {
        String msg =  (e + "\n  " + name + " in " + this
            + "\n  exists in " + findPath(className)
            + "\n  check for missing dependencies");
        
        log().fine(msg);
        
        throw new ClassNotFoundException(e.getMessage() + "\n" + msg, e);
      }
      
      throw e;
    }
  }
486537
private Map findLoaders() {
        Map loaders = getContainer().getComponentDescriptorMap(ProviderLoader.class.getName());
        if (loaders == null) {
            throw new Error("No provider loaders found");
        }

        Set keys = loaders.keySet();
        Map found = null;
        ProviderLoader defaultLoader = null;

        for (Iterator iter = keys.iterator(); iter.hasNext();) {
            String key = (String)iter.next();

            ProviderLoader loader;

            try {
                loader = (ProviderLoader) getContainer().lookup(ProviderLoader.class.getName(), key);
            }
            catch (Exception e) {
                log.warn("Failed to lookup provider loader for key: {}", key, e);
                continue;
            }

            if (loader != null) {
                if (found == null) {
                    // we need an ordered map
                    found = new LinkedHashMap();
                }
                if (key.equals(SELECT_DEFAULT)) {
                    defaultLoader = loader;
                }
                else {
                    found.put(key, loader);
                }
            }
        }

        // the default should be added at the end (as fallback)
        assert defaultLoader != null;
        found.put(SELECT_DEFAULT, defaultLoader);

        return found;
    }
426447
public ClassLoader getUserCodeClassLoader() {
		if (this.userCodeClassLoader == null) {
			this.userCodeClassLoader = buildUserCodeClassLoader(jarFiles, classpaths, getClass().getClassLoader());
		}
		return this.userCodeClassLoader;
	}
670322
protected static ClassLoader getContextClassLoader()
    {
        if (System.getSecurityManager() != null)
        {
            try
            {
                Object cl = AccessController.doPrivileged(new PrivilegedExceptionAction()
                {
                            public Object run() throws PrivilegedActionException
                            {
                                return Thread.currentThread().getContextClassLoader();
                            }
                });
                return (ClassLoader) cl;
            }
            catch (PrivilegedActionException pae)
            {
                throw new FacesException(pae);
            }
        }
        else
        {
            return Thread.currentThread().getContextClassLoader();
        }
    }
668261
public static ClassLoader getClassLoader(Class<?> clazz) {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader != null) {
            return loader;
        }
        if (clazz != null) {
            loader = clazz.getClassLoader();
            if (loader != null) {
                return loader;
            }
        }
        return ClassLoader.getSystemClassLoader();
    }
946042
private ClassLoader resolve(Set<? extends File> classPath) {
        ClassLoader classLoader = classLoaders.get(classPath);
        if (classLoader == null) {
            classLoader = doResolve(classPath);
            classLoaders.put(classPath, classLoader);
        }
        return classLoader;
    }
901368
@FFDCIgnore(ClassNotFoundException.class)
    private Class<?> findClassCommonLibraryClassLoaders(String name) throws ClassNotFoundException {
        for (LibertyLoader cl : delegateLoaders) {
            try {
                return cl.findClass(name);
            } catch (ClassNotFoundException e) {
                // Ignore. Will throw at the end if class is not found.
            }
        }
        // If we reached here, then the class was not loaded.
        throw new ClassNotFoundException(name);
    }
1044245
@Override
  public ClassLoader getClassLoader() {
    URL[] urlsForClassLoader = new URL[urls.size()];
    urls.toArray(urlsForClassLoader);

    URLClassLoader classLoader = new URLClassLoader(urlsForClassLoader);
    Thread.currentThread().setContextClassLoader(classLoader);

    return classLoader;
  }
890967
@Override
    public JavaClass findClass(/*@Nonnull*/ String className) {
        // Make sure we handle class names with slashes.
        // If we don't, we can get into serious trouble: a previously
        // loaded class will appear to be missing (because we're using the
        // wrong name to look it up) and be evicted by some other random
        // version of the class loaded from the classpath.
        String dottedClassName = className.replace('/', '.');

        return nameToClassMap.get(dottedClassName);
    }
192869
private Class<?> attemptFromContextLoader(final String driverClassName) {
      final ClassLoader threadContextClassLoader = Thread.currentThread().getContextClassLoader();
      if (threadContextClassLoader != null) {
         try {
            final Class<?> driverClass = threadContextClassLoader.loadClass(driverClassName);
            LOGGER.debug("Driver class {} found in Thread context class loader {}", driverClassName, threadContextClassLoader);
            return driverClass;
         } catch (ClassNotFoundException e) {
            LOGGER.debug("Driver class {} not found in Thread context class loader {}, trying classloader {}",
               driverClassName, threadContextClassLoader, this.getClass().getClassLoader());
         }
      }

      return null;
   }
444904
public static ClassLoader getDefaultClassLoader(Class<?> clazz) {
		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
		if (classLoader == null) {
			classLoader = clazz.getClassLoader();
		}
		return classLoader;
	}
720609
public static ApplicationContext get() {
        ClassLoader classLoader = getContextClassLoader();
        while (classLoader != null) {
            ApplicationContext applicationContext = contextMap.get(classLoader);
            if (applicationContext != null) {
                return applicationContext;
            }
            classLoader = classLoader.getParent();
        }
        return null;
    }
730630
private final URL[] findResourcesByContextLoader()
    {
        List<URL> list = new ArrayList<URL>();
        ClassLoader classLoader = this.getClass().getClassLoader();
        assert classLoader != null;        
        URL[] urls = ((URLClassLoader) classLoader).getURLs();
        
        for (String fullyQualifiedClassName : classesToScan)
        {
            String classRelativePath = fullyQualifiedClassName.replace(".", "/");
            list.addAll(Arrays.asList(findResourcesInUrls(classRelativePath, urls)));
        }

        return list.toArray(new URL[list.size()]);
    }
1039777
public static Class<?> loadClass(String name, boolean init, ClassLoader loader)
    throws ClassNotFoundException
  {
    if (loader == null)
      loader = Thread.currentThread().getContextClassLoader();

    if (loader == null || loader.equals(CauchoUtil.class.getClassLoader()))
      return Class.forName(name);
    else
      return Class.forName(name, init, loader);
  }
296571
public final UserManagedCacheBuilder<K, V, T> withClassLoader(ClassLoader classLoader) {
    if (classLoader == null) {
      throw new NullPointerException("Null classloader");
    }
    UserManagedCacheBuilder<K, V, T> otherBuilder = new UserManagedCacheBuilder<>(this);
    otherBuilder.classLoader = classLoader;
    return otherBuilder;
  }
1321063
@Pure
	public static ClassLoader getContextClassLoader() throws AndroidException {
		synchronized (Android.class) {
			final ClassLoader cl = (contextClassLoader == null) ? null : contextClassLoader.get();
			if (cl != null) {
				return cl;
			}
		}
		final Object context = getContext();
		try {
			final Method method = context.getClass().getMethod("getClassLoader"); //$NON-NLS-1$
			final Object classLoader = method.invoke(context);
			final ClassLoader cl = (ClassLoader) classLoader;
			synchronized (Android.class) {
				contextClassLoader = new WeakReference<>(cl);
			}
			return cl;
		} catch (Exception e) {
			throw new AndroidException(e);
		}
	}