public static boolean closeClassLoadersTo(ClassLoader current, ClassLoader stop) {
    if (!isValidHierarchy(current, stop)) {
      return false;
    }
    for (; current != null && current != stop; current = current.getParent()) {
      try {
        closeClassLoader(current);
      } catch (IOException e) {
        String detailedMessage = (current instanceof URLClassLoader urlcl) ?
            Arrays.toString(urlcl.getURLs()) :
            "";
        LOG.info("Failed to close class loader " + current + " " + detailedMessage, e);
      }
    }
    return true;
  }
Standard way of getting classloader in Hive code (outside of Hadoop).

Uses the context loader to get access to classpaths to auxiliary and jars
added with 'add jar' command. Falls back to current classloader.

In Hadoop-related code, we use Configuration.getClassLoader().
common/src/java/org/apache/hadoop/hive/common/JavaUtils.java