Class AccessUtil


  • public class AccessUtil
    extends java.lang.Object
    Utilities for private access
    • Constructor Summary

      Constructors 
      Constructor Description
      AccessUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object accessField​(java.lang.String fieldName, java.lang.Object owner)
      Fetches a private field from an object
      static java.lang.Object accessFieldOrNull​(java.lang.String fieldName, java.lang.Object owner)
      Fetches a private field from an object, or returns NULL if there was an error
      static java.lang.Object callMethod​(java.lang.String methodName, java.lang.Object owner, java.lang.Object... args)
      Call a private method from an object
      static java.lang.Object callMethodOrNull​(java.lang.String methodName, java.lang.Object owner, java.lang.Object... args)
      Call a private method from an object or return NULL if there was an error
      • Methods inherited from class java.lang.Object

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

      • AccessUtil

        public AccessUtil()
    • Method Detail

      • accessField

        public static java.lang.Object accessField​(java.lang.String fieldName,
                                                   java.lang.Object owner)
                                            throws java.lang.IllegalArgumentException,
                                                   java.lang.IllegalAccessException,
                                                   java.lang.NoSuchFieldException,
                                                   java.lang.SecurityException
        Fetches a private field from an object
        Parameters:
        fieldName - Name of the field
        owner - Object to fetch from
        Returns:
        Value
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalAccessException
        java.lang.NoSuchFieldException
        java.lang.SecurityException
      • accessFieldOrNull

        public static java.lang.Object accessFieldOrNull​(java.lang.String fieldName,
                                                         java.lang.Object owner)
        Fetches a private field from an object, or returns NULL if there was an error
        Parameters:
        fieldName - Name of the field
        owner - Object to fetch from
        Returns:
        Value or NULL
      • callMethod

        public static java.lang.Object callMethod​(java.lang.String methodName,
                                                  java.lang.Object owner,
                                                  java.lang.Object... args)
                                           throws java.lang.NoSuchMethodException,
                                                  java.lang.SecurityException,
                                                  java.lang.IllegalAccessException,
                                                  java.lang.IllegalArgumentException,
                                                  java.lang.reflect.InvocationTargetException
        Call a private method from an object
        Parameters:
        methodName - Name of the method
        owner - Object that owns the method
        args - Method arguments
        Returns:
        Method output
        Throws:
        java.lang.NoSuchMethodException
        java.lang.SecurityException
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException
      • callMethodOrNull

        public static java.lang.Object callMethodOrNull​(java.lang.String methodName,
                                                        java.lang.Object owner,
                                                        java.lang.Object... args)
        Call a private method from an object or return NULL if there was an error
        Parameters:
        methodName - Name of the method
        owner - Object that owns the method
        args - Method arguments
        Returns:
        Method output or NULL