Class ClassLoaderUtils


  • @API(status=INTERNAL,
         since="1.0")
    public final class ClassLoaderUtils
    extends java.lang.Object
    Collection of utilities for working with ClassLoader and associated tasks.

    DISCLAIMER

    These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!

    Since:
    1.0
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ClassLoaderUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.ClassLoader getClassLoader​(java.lang.Class<?> clazz)
      Get the ClassLoader for the supplied Class, falling back to the default class loader if the class loader for the supplied class is null.
      static java.lang.ClassLoader getDefaultClassLoader()  
      static java.util.Optional<java.net.URL> getLocation​(java.lang.Object object)
      Get the location from which the supplied object's class was loaded.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClassLoaderUtils

        private ClassLoaderUtils()
    • Method Detail

      • getClassLoader

        public static java.lang.ClassLoader getClassLoader​(java.lang.Class<?> clazz)
        Get the ClassLoader for the supplied Class, falling back to the default class loader if the class loader for the supplied class is null.
        Parameters:
        clazz - the class for which to retrieve the class loader; never null
        Since:
        1.10
      • getDefaultClassLoader

        public static java.lang.ClassLoader getDefaultClassLoader()
      • getLocation

        public static java.util.Optional<java.net.URL> getLocation​(java.lang.Object object)
        Get the location from which the supplied object's class was loaded.
        Parameters:
        object - the object for whose class the location should be retrieved
        Returns:
        an Optional containing the URL of the class' location; never null but potentially empty