001package org.junit.internal;
002
003import static java.lang.Thread.currentThread;
004
005/**
006 * Miscellaneous functions dealing with classes.
007 */
008public class Classes {
009
010    /**
011     * Do not instantiate.
012     * @deprecated will be private soon.
013     */
014    @Deprecated
015    public Classes() {
016    }
017
018    /**
019     * Returns Class.forName for {@code className} using the current thread's class loader.
020     * If the current thread does not have a class loader, falls back to the class loader for
021     * {@link Classes}.
022     *
023     * @param className Name of the class.
024     * @throws ClassNotFoundException
025     */
026    public static Class<?> getClass(String className) throws ClassNotFoundException {
027        return getClass(className, Classes.class);
028    }
029
030    /**
031     * Returns Class.forName for {@code className} using the current thread's class loader.
032     * If the current thread does not have a class loader, falls back to the class loader for the
033     * passed-in class.
034     *
035     * @param className Name of the class.
036     * @param callingClass Class that is requesting a the class
037     * @throws ClassNotFoundException
038     * @since 4.13
039     */
040    public static Class<?> getClass(String className, Class<?> callingClass) throws ClassNotFoundException {
041        ClassLoader classLoader = currentThread().getContextClassLoader();
042        return Class.forName(className, true, classLoader == null ? callingClass.getClassLoader() : classLoader);
043    }
044}