public class ClassLoaderReflectionToolkit extends Object
ClassLoader
methods which are otherwise protected
.
Initially tries to access methods using known classloaders in use that expose the methods
to prevent illegal reflective access errors on Java 11+
Then falls back to accessing the ClassLoader
methods.
All reflection method initialisation is delayed until first use so that we don't access the methods if we don't need to.
Note: Currently there is no known production use-case for the fallback case of accessing these methods via reflection:
the JenkinsRule
tests use a different classloader,
but once that is made consistent with production Jenkins we can re-evaluate the fallback code.
Constructor and Description |
---|
ClassLoaderReflectionToolkit()
Deprecated.
unsafe
|
Modifier and Type | Method and Description |
---|---|
static Class<?> |
_findClass(ClassLoader cl,
String name)
Calls
ClassLoader.findClass(java.lang.String) while holding ClassLoader.getClassLoadingLock(java.lang.String) . |
static Class<?> |
_findLoadedClass(ClassLoader cl,
String name)
|
static URL |
_findResource(ClassLoader cl,
String name)
|
static Enumeration<URL> |
_findResources(ClassLoader cl,
String name)
|
Class |
findClass(ClassLoader cl,
String name)
Deprecated.
unsafe
|
Class |
findLoadedClass(ClassLoader cl,
String name)
Deprecated.
unsafe
|
URL |
findResource(ClassLoader cl,
String name)
Deprecated.
unsafe
|
Enumeration<URL> |
findResources(ClassLoader cl,
String name)
Deprecated.
unsafe
|
@Deprecated public ClassLoaderReflectionToolkit()
@CheckForNull public static Class<?> _findLoadedClass(ClassLoader cl, String name)
ClassLoader.findLoadedClass(java.lang.String)
while holding ClassLoader.getClassLoadingLock(java.lang.String)
.@NonNull public static Class<?> _findClass(ClassLoader cl, String name) throws ClassNotFoundException
ClassLoader.findClass(java.lang.String)
while holding ClassLoader.getClassLoadingLock(java.lang.String)
.ClassNotFoundException
@CheckForNull public static URL _findResource(ClassLoader cl, String name)
@NonNull public static Enumeration<URL> _findResources(ClassLoader cl, String name) throws IOException
IOException
@Deprecated public Class findLoadedClass(ClassLoader cl, String name) throws InvocationTargetException
InvocationTargetException
@Deprecated public Class findClass(ClassLoader cl, String name) throws InvocationTargetException
InvocationTargetException
@Deprecated public URL findResource(ClassLoader cl, String name) throws InvocationTargetException
InvocationTargetException
@Deprecated public Enumeration<URL> findResources(ClassLoader cl, String name) throws InvocationTargetException
InvocationTargetException
Copyright © 2004–2021. All rights reserved.