Class ReflectionUtils


  • public final class ReflectionUtils
    extends java.lang.Object
    Provide utilities to assist reflective access. This class is forked from the netty project and modified to suit our needs.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.reflect.Method retrieveMethod​(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes)
      Retrieves the specific Method from the Class without checked exception.
      static java.lang.Throwable trySetAccessible​(java.lang.reflect.AccessibleObject object, boolean checkAccessible)
      Try to call AccessibleObject.setAccessible(boolean) but will catch any SecurityException and java.lang.reflect.InaccessibleObjectException (for JDK 9) and return it.
      • Methods inherited from class java.lang.Object

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

      • retrieveMethod

        public static java.lang.reflect.Method retrieveMethod​(java.lang.Class<?> clazz,
                                                              java.lang.String name,
                                                              java.lang.Class<?>... parameterTypes)
        Retrieves the specific Method from the Class without checked exception.

        Throws IllegalArgumentException if NoSuchMethodException is thrown.

        Parameters:
        clazz - Class to retrieve a Method from
        name - the name of the method
        parameterTypes - the list of method parameters
        Returns:
        the Method object
      • trySetAccessible

        @Nullable
        public static java.lang.Throwable trySetAccessible​(java.lang.reflect.AccessibleObject object,
                                                           boolean checkAccessible)
        Try to call AccessibleObject.setAccessible(boolean) but will catch any SecurityException and java.lang.reflect.InaccessibleObjectException (for JDK 9) and return it. The caller must check if it returns null and if not handle the returned exception.
        Parameters:
        object - The object to attempt to make accessible.
        checkAccessible - true to respect system property configuration which may limit AccessibleObject.setAccessible(boolean) attempts. false to try regardless of system property configuration.
        Returns:
        a Throwable indicating the exception that occurred while attempting to make object accessible, or null if the operation was successful.