public static void closeClassLoader(ClassLoader loader) throws IOException {
    if (loader instanceof Closeable closeable) {
      closeable.close();
    } else {
      LOG.warn("Ignoring attempt to close class loader ({}) -- not instance of UDFClassLoader.",
          loader == null ? "mull" : loader.getClass().getSimpleName());
    }
  }
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