Calls {@link ClassLoader#findLoadedClass} while holding {@link ClassLoader#getClassLoadingLock}.
@since 1.553
499615
public static @CheckForNull Class<?> _findLoadedClass(ClassLoader cl, String name) {
        synchronized (getClassLoadingLock(cl, name)) {
            return (Class) invoke(FIND_LOADED_CLASS, RuntimeException.class, cl, name);
        }
    }
127798
@Override
    public Class<?> loadClass(String classname) throws ClassNotFoundException {
        return getClass().getClassLoader().loadClass(classname);
    }
28599
public static ClassLoader getClassLoader(Class<?> cls) {
        ClassLoader cl = cls.getClassLoader();
        if (cl == null) {
            cl = getClassLoader();
        }
        return cl;
    }
591763
@Override
    public ClassLoader getThrowawayClassLoader() {
        ClassLoader newParent = getThrowawayVersion(getParent());
        ClassLoader[] newFollowOns = new ClassLoader[followOnClassLoaders.size()];
        for (int i = 0; i < newFollowOns.length; i++) {
            newFollowOns[i] = getThrowawayVersion(followOnClassLoaders.get(i));
        }
        return new UnifiedClassLoader(newParent, newFollowOns);
    }
318958
private static Class getByClass(String name) {
        try {
            return Thread.currentThread().getContextClassLoader().loadClass(name);
        } catch (Throwable e) {
        }
        return null;
    }
1012402
@SuppressWarnings("unchecked")
    public static boolean findClass(String className) {
        try {
            return getClassLoader().loadClass(className) != null;
        } catch (ClassNotFoundException e) {
            return false;
        } catch (NoClassDefFoundError e) {
            return false;
        }
    }
310764
public static ClassLoader getContextClassLoader() {
        ClassLoader loader = null;
        try {
            loader = Thread.currentThread().getContextClassLoader();
        } catch (Throwable e) {
        }
        if (loader == null) {
            loader = ClassUtils.class.getClassLoader();
        }
        return loader;
    }
193872
static Class<?> findClassFromClassLoaders(final String className, final Iterable<ClassLoader> classLoaders)
        throws ClassNotFoundException, IllegalArgumentException {
        // Precondition checks
        assert className != null && className.length() > 0 : "Class Name must be specified";
        assert classLoaders != null : "ClassLoaders as search path must be specified";

        // Find the class by searching through the CLs in order
        Class<?> clazz = null;
        for (final ClassLoader cl : classLoaders) {
            try {
                clazz = Class.forName(className, false, cl);
                if (log.isLoggable(Level.FINER)) {
                    log.finer("Found requested class " + clazz.getName() + " from ClassLoader "
                        + clazz.getClassLoader());
                }
            } catch (final ClassNotFoundException cnfe) {
                // Ignore here, try the next
            }

        }
        // If we haven't got a class yet, now we need to show we've got CNFE
        if (clazz == null) {
            throw new ClassNotFoundException("Could not find requested class \"" + className
                + "\" in any of the associated ClassLoaders: " + classLoaders);
        }

        // Return
        return clazz;
    }
987215
public static @Nonnull Class<?> _findClass(ClassLoader cl, String name) throws ClassNotFoundException {
        synchronized (getClassLoadingLock(cl, name)) {
            return (Class) invoke(FIND_CLASS, ClassNotFoundException.class, cl, name);
        }
    }
424156
public ClassLoader getClassLoader ()
  {
    // To follow the same behavior of Class.forName(...) I had to play
    // dirty (Supported by Sun, IBM & BEA JVMs)
    try
    {
      // Get a reference to this class' class-loader
      final ClassLoader cl = getClass ().getClassLoader ();

      // Create a method instance representing the protected
      // getCallerClassLoader method of class ClassLoader
      final Method mthd = ClassLoader.class.getDeclaredMethod ("getCallerClassLoader", new Class <?> [0]);
      if (false)
      {
        // Make the method accessible.
        AccessibleObject.setAccessible (new AccessibleObject [] { mthd }, true);
      }
      // Try to get the caller's class-loader
      return (ClassLoader) mthd.invoke (cl, new Object [0]);
    }
    catch (final Throwable all)
    {
      // Use this class' class-loader
      return getClass ().getClassLoader ();
    }
  }
1050886
public static Class get(String clazzname, ClassLoader loader) throws ClassNotFoundException {
        return Util.loadClass(clazzname, loader != null? loader : ClassConfigurator.class.getClassLoader());
    }
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;
  }
82827
public static Class<?> getCallingClass() {
        ClassContextSecurityManager securityManager = getSecurityManager();
        if (securityManager == null)
            return null;
        Class<?>[] trace = securityManager.getClassContext();
        String thisClassName = Util.class.getName();

        // Advance until Util is found
        int i;
        for (i = 0; i < trace.length; i++) {
            if (thisClassName.equals(trace[i].getName()))
                break;
        }

        // trace[i] = Util; trace[i+1] = caller; trace[i+2] = caller's caller
        if (i >= trace.length || i + 2 >= trace.length) {
            throw new IllegalStateException("Failed to find org.slf4j.helpers.Util or its caller in the stack; " + "this should not happen");
        }

        return trace[i + 2];
    }
945687
private static Class<? extends StackTraceElement> findClassCaller()
    {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

        for( int i = 2; i < stackTrace.length; i++ )
        {
            StackTraceElement call = stackTrace[i];
            if (!Log.class.isAssignableFrom(call.getClass()))
                return call.getClass();
        }

        return null;
    }
569963
@Override
  public ClassLoader getClassLoader() {

    // To follow the same behavior of Class.forName(...) I had to play
    // dirty (Supported by Sun, IBM & BEA JVMs)
    try {
      // Get a reference to this class' class-loader
      ClassLoader cl = this.getClass().getClassLoader();
      // Create a method instance representing the protected
      // getCallerClassLoader method of class ClassLoader
      Method mthd = ClassLoader.class.getDeclaredMethod("getCallerClassLoader", new Class[0]);
      // Make the method accessible.
      AccessibleObject.setAccessible(new AccessibleObject[] {mthd}, true);
      // Try to get the caller's class-loader
      return (ClassLoader) mthd.invoke(cl, new Object[0]);
    } catch (Exception all) {
      // Use this class' class-loader
      return this.getClass().getClassLoader();
    }
  }
445401
@Override
  public ClassLoader getClassLoader() {

    return (this.bestCandidate == null)
        ? Thread.currentThread().getContextClassLoader()
        : this.bestCandidate.getClassLoader();
  }
1135316
public static List<ClassLoader> getClassLoaders() {
        ClassLoader[] classLoaders = new ClassLoader[2];
        classLoaders[0] = FileUtils.class.getClassLoader();
        classLoaders[1] = Thread.currentThread().getContextClassLoader();

        // Clean up possible null values. Note that #getClassLoader may return a null value.
        List<ClassLoader> loaders = new ArrayList<ClassLoader>(classLoaders.length);
        for (ClassLoader classLoader : classLoaders) {
            if (classLoader != null) {
                loaders.add(classLoader);
            }
        }
        return loaders;
    }