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) {
    return true;
  }
}

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 ) { return true ; } }
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 .
