Class ClassReflection


  • public class ClassReflection
    extends java.lang.Object
    When we try to access methods through reflection in a JVM that uses a SecurityManager (when we're running in WebSphere, for example), we get access exceptions when calling the reflection apis from most of the agent code. This class is loaded on the bootstrap classloader and has permission to call these apis. Note that it still fails when trying to invoke Method.setAccessible(boolean). Don't delete methods off of this class. While the IDE might not find direct callers, many methods are invoked through rewritten instructions in weaved classes.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object get​(java.lang.reflect.Field field, java.lang.Object instance)  
      static java.lang.ClassLoader getClassLoader​(java.lang.Class<?> clazz)  
      static java.lang.reflect.Constructor<?>[] getDeclaredConstructors​(java.lang.Class<?> clazz)  
      static java.lang.reflect.Field getDeclaredField​(java.lang.Class<?> clazz, java.lang.String name)  
      static java.lang.reflect.Field[] getDeclaredFields​(java.lang.Class<?> clazz)  
      static java.lang.reflect.Method getDeclaredMethod​(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes)  
      static java.lang.reflect.Method[] getDeclaredMethods​(java.lang.Class<?> clazz)  
      static java.lang.reflect.Method[] getMethods​(java.lang.Class<?> clazz)  
      static java.lang.Class<?> loadClass​(java.lang.ClassLoader classLoader, java.lang.String name)  
      static void setAccessible​(java.lang.reflect.Field field, boolean flag)  
      static void setAccessible​(java.lang.reflect.Method method, boolean flag)  
      • Methods inherited from class java.lang.Object

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

      • getClassLoader

        public static java.lang.ClassLoader getClassLoader​(java.lang.Class<?> clazz)
      • loadClass

        public static java.lang.Class<?> loadClass​(java.lang.ClassLoader classLoader,
                                                   java.lang.String name)
                                            throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • getDeclaredMethods

        public static java.lang.reflect.Method[] getDeclaredMethods​(java.lang.Class<?> clazz)
        See Also:
        Class.getDeclaredMethods()
      • getDeclaredMethod

        public static java.lang.reflect.Method getDeclaredMethod​(java.lang.Class<?> clazz,
                                                                 java.lang.String name,
                                                                 java.lang.Class<?>... parameterTypes)
                                                          throws java.lang.NoSuchMethodException,
                                                                 java.lang.SecurityException
        Throws:
        java.lang.NoSuchMethodException
        java.lang.SecurityException
        See Also:
        Class.getDeclaredMethod(String, Class...)
      • getMethods

        public static java.lang.reflect.Method[] getMethods​(java.lang.Class<?> clazz)
        See Also:
        Class.getMethods()
      • getDeclaredConstructors

        public static java.lang.reflect.Constructor<?>[] getDeclaredConstructors​(java.lang.Class<?> clazz)
        See Also:
        Class.getDeclaredConstructors()
      • getDeclaredFields

        public static java.lang.reflect.Field[] getDeclaredFields​(java.lang.Class<?> clazz)
        See Also:
        Class.getDeclaredFields()
      • getDeclaredField

        public static java.lang.reflect.Field getDeclaredField​(java.lang.Class<?> clazz,
                                                               java.lang.String name)
                                                        throws java.lang.NoSuchFieldException,
                                                               java.lang.SecurityException
        Throws:
        java.lang.NoSuchFieldException
        java.lang.SecurityException
      • get

        public static java.lang.Object get​(java.lang.reflect.Field field,
                                           java.lang.Object instance)
                                    throws java.lang.IllegalArgumentException,
                                           java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalAccessException
      • setAccessible

        public static void setAccessible​(java.lang.reflect.Field field,
                                         boolean flag)
                                  throws java.lang.IllegalArgumentException,
                                         java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalAccessException
      • setAccessible

        public static void setAccessible​(java.lang.reflect.Method method,
                                         boolean flag)
                                  throws java.lang.IllegalArgumentException,
                                         java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalAccessException