Class ReflectionUtils

java.lang.Object
io.servicetalk.utils.internal.ReflectionUtils

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

    • retrieveMethod

      public static Method retrieveMethod(Class<?> clazz, String name, 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 Throwable trySetAccessible(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.