code: @SuppressWarnings("unchecked")
    public static <T> Class<T> forNameEx(String className) throws ClassNotFoundException, ClassCastException, NullPointerException
    {
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      ClassNotFoundException classNotFoundException = null;
      if(loader != null) {
        try {
          return (Class<T>)Class.forName(className, true, loader);
        }
        catch(ClassNotFoundException expected) {
          classNotFoundException = expected;
        }
      }
  
      // try library class loader only if not the same as current thread context class loader, already tried
      if(classNotFoundException != null && loader.equals(Classes.class.getClassLoader())) {
        throw classNotFoundException;
      }
      return (Class<T>)Class.forName(className, true, Classes.class.getClassLoader());
    }
docs: Get class by name with checked exception. The same as {@link #forName(String)} but throws checked exception in the
  event requested class is not found.
  
  @param className requested class name, not null.
  @param <T> class to auto-cast named class.
  @return class identified by name.
  @throws ClassNotFoundException if class not found.
  @throws ClassCastException if found class cannot cast to requested auto-cast type.
  @throws NullPointerException if <code>className</code> argument is null.