Check whether the given class is cache-safe in the given context,
i.e. whether it is loaded by the given ClassLoader or a parent of it.
@param clazz the class to analyze
@param classLoader the ClassLoader to potentially cache metadata in
193922
public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
		Assert.notNull(clazz, "Class must not be null");
		try {
			ClassLoader target = clazz.getClassLoader();
			if (target == null) {
				return true;
			}
			ClassLoader cur = classLoader;
			if (cur == target) {
				return true;
			}
			while (cur != null) {
				cur = cur.getParent();
				if (cur == target) {
					return true;
				}
			}
			return false;
		}
		catch (SecurityException ex) {
			// Probably from the system ClassLoader - let's consider it safe.
			return true;
		}
	}
419548
public static void initializeClass(Class clazz) {
		try {
			Class.forName(clazz.getName(), true, Thread.currentThread().getContextClassLoader());
		}
		catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}
1067189
@Override
    public <T> List<T> loadAllDataFromCache(final Class<T> clazz) throws CacheLoadingException, CacheCreationException {
        return getObjectPersister(clazz).loadAllDataFromCache();
    }
952226
public static ClassLoader getClassLoader(final Class<?> clazz) {
        // Context class loader can be null
        final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        if (contextClassLoader != null) {
            return contextClassLoader;
        }
        if (clazz != null) {
            // The class loader for a specific class can also be null
            final ClassLoader clazzClassLoader = clazz.getClassLoader();
            if (clazzClassLoader != null) {
                return clazzClassLoader;
            }
        }
        // The only class loader we can rely on for not being null is the system
        // one
        return ClassLoader.getSystemClassLoader();
    }
69867
public static <A extends Annotation> A getAnnotation(final Class<?> clazz, Class<A> annoClazz) {
        if (clazz == null || annoClazz == null) {
            return null;
        }

        return clazz.getAnnotation(annoClazz);
    }
1183077
public static ClassResolver softCachingResolver(ClassLoader classLoader) {
        return new CachingClassResolver(
                new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
                new SoftReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
    }
645703
public <T> Clazz<T> Clazz( Class<T> clazz )
	{
		_ensureMap();

		@SuppressWarnings( "unchecked" )
		Clazz<T> res = (Clazz<T>) clazzz.get( clazz );
		if( res == null )
			throw new IllegalArgumentException( "Class not supported by ClassInfo : " + clazz.getName() );

		return res;
	}
868295
public void setClassLoader(GroovyClassLoader loader) {
        ClassLoader parent = Thread.currentThread().getContextClassLoader();
        if (parent == null) parent = ProcessingUnit.class.getClassLoader();
        this.classLoader = (loader == null ? new GroovyClassLoader(parent, configuration) : 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;
  }
804140
public CacheConfigurationBuilder<K, V> withClassLoader(ClassLoader classLoader) {
    CacheConfigurationBuilder<K, V> otherBuilder = new CacheConfigurationBuilder<>(this);
    otherBuilder.classLoader = classLoader;
    return otherBuilder;
  }
393188
private static boolean isKnownClassLoaderAccessibleFrom(final ClassLoader accessibleCL, final ClassLoader fromCL) {

        if (fromCL == null) {
            return false;
        }

        ClassLoader parent = fromCL;

        try {

            while (parent != null && parent != accessibleCL) {
                parent = parent.getParent();
            }

            return (parent != null && parent == accessibleCL);

        } catch (final SecurityException se) {
            // The SecurityManager prevents us from accessing, so just ignore it
            return false;
        }

    }
942859
private boolean checkValidClass(Class<?> clazz) {
        return clazz.isAnnotationPresent(Entity.class) || clazz.isAnnotationPresent(MappedSuperclass.class)
            || clazz.isAnnotationPresent(Embeddable.class);

    }
1143304
@Override
  public ClassSignature getClassFromClassLoader(final String clazz) throws ClassNotFoundException,IOException {
    if (classpathClassCache.containsKey(clazz)) {
      final ClassSignature c = classpathClassCache.get(clazz);
      if (c == null) {
        throw new ClassNotFoundException(clazz);
      }
      return c;
    } else {
      final URL url = loader.getResource(AsmUtils.getClassResourceName(clazz));
      if (url != null) {
        final URLConnection conn = url.openConnection();
        final boolean isRuntimeClass = isRuntimeClass(conn);
        if (!isRuntimeClass && options.contains(Option.DISABLE_CLASSLOADING_CACHE)) {
          conn.setUseCaches(false);
        }
        final InputStream in = conn.getInputStream();
        final ClassReader cr;
        try {
          cr = AsmUtils.readAndPatchClass(in);
        } catch (IllegalArgumentException iae) {
          // if class is too new for this JVM, we try to load it as Class<?> via Jigsaw
          // (only if it's a runtime class):
          if (isRuntimeClass) {
            final ClassSignature c = loadClassFromJigsaw(clazz);
            if (c != null) {
              classpathClassCache.put(clazz, c);
              return c;
            }
          }
          // unfortunately the ASM IAE has no message, so add good info!
          throw new IllegalArgumentException(String.format(Locale.ENGLISH,
              "The class file format of '%s' (loaded from location '%s') is too recent to be parsed by ASM.",
              clazz, url.toExternalForm()));
        } finally {
          in.close();
        }
        final ClassSignature c = new ClassSignature(cr, isRuntimeClass, false);
        classpathClassCache.put(clazz, c);
        return c;
      } else {
        final ClassSignature c = loadClassFromJigsaw(clazz);
        if (c != null) {
          classpathClassCache.put(clazz, c);
          return c;
        }
      }
      // try to get class from our list of classes we are checking:
      final ClassSignature c = classesToCheck.get(clazz);
      if (c != null) {
        classpathClassCache.put(clazz, c);
        return c;
      }
      // all failed => the class does not exist!
      classpathClassCache.put(clazz, null);
      throw new ClassNotFoundException(clazz);
    }
  }
690358
public static boolean isDataClass(final Class<?> clazz) {

    if (clazz == null || clazz.isPrimitive()) {
      return true;
    }
    boolean isWrapperClass = contains(WRAPPER_CLASSES, clazz);
    if (isWrapperClass) {
      return true;
    }
    boolean isDataClass = contains(DATA_PRIMITIVE_CLASS, clazz);
    if (isDataClass) {
      return true;
    }
    return false;
  }
869160
@SuppressWarnings("rawtypes")
	public static Class loadClass(Class loadClass, String name,
								  boolean checkParents) throws ClassNotFoundException {
		ClassNotFoundException ex = null;
		Class<?> c = null;
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		while (c == null && loader != null) {
			try {
				c = loader.loadClass(name);
			} catch (ClassNotFoundException e) {
				if (ex == null) {
					ex = e;
				}
			}
			loader = (c == null && checkParents) ? loader.getParent() : null;
		}

		loader = loadClass == null ? null : loadClass.getClassLoader();
		while (c == null && loader != null) {
			try {
				c = loader.loadClass(name);
			} catch (ClassNotFoundException e) {
				if (ex == null) {
					ex = e;
				}
			}
			loader = (c == null && checkParents) ? loader.getParent() : null;
		}

		if (c == null) {
			try {
				c = Class.forName(name);
			} catch (ClassNotFoundException e) {
				if (ex == null) {
					ex = e;
				}
			}
		}

		if (c != null) {
			return c;
		}
		throw ex;
	}
1168258
public static ClassResolver weakCachingResolver(ClassLoader classLoader) {
        return new CachingClassResolver(
                new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
                new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
    }
296406
public static void findClassLoaderOrder(final ClassLoader classLoader,
            final ClassLoaderOrder classLoaderOrder) {
        classLoaderOrder.delegateTo(
                (ClassLoader) ReflectionUtils.getFieldVal(classLoader, "parentContextClassLoader", false),
                /* isParent = */ true);
        classLoaderOrder.delegateTo(classLoader.getParent(), /* isParent = */ true);
        classLoaderOrder.add(classLoader);
    }