Package io.servicetalk.utils.internal
Class ReflectionUtils
- java.lang.Object
-
- io.servicetalk.utils.internal.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 specificMethod
from theClass
without checked exception.static java.lang.Throwable
trySetAccessible(java.lang.reflect.AccessibleObject object, boolean checkAccessible)
Try to callAccessibleObject.setAccessible(boolean)
but will catch anySecurityException
andjava.lang.reflect.InaccessibleObjectException
(for JDK 9) and return it.
-
-
-
Method Detail
-
retrieveMethod
public static java.lang.reflect.Method retrieveMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes)
Retrieves the specificMethod
from theClass
without checked exception.Throws
IllegalArgumentException
ifNoSuchMethodException
is thrown.- Parameters:
clazz
-Class
to retrieve aMethod
fromname
- the name of the methodparameterTypes
- 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 callAccessibleObject.setAccessible(boolean)
but will catch anySecurityException
andjava.lang.reflect.InaccessibleObjectException
(for JDK 9) and return it. The caller must check if it returnsnull
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 limitAccessibleObject.setAccessible(boolean)
attempts.false
to try regardless of system property configuration.- Returns:
- a
Throwable
indicating the exception that occurred while attempting to makeobject
accessible, ornull
if the operation was successful.
-
-