public static < T > T accessMember ( final AccessibleObject member , final Callable < T > callable , String errorMessage ) { if ( callable == null ) { return null ; } return AccessController . doPrivileged ( ( PrivilegedAction < T > ) ( ) -> { boolean wasAccessible = member . isAccessible ( ) ; try { member . setAccessible ( true ) ; return callable . call ( ) ; } catch ( Exception exception ) { throw new IllegalStateException ( errorMessage , exception ) ; } finally { member . setAccessible ( wasAccessible ) ; } } ) ; }
Helper method to execute a callback on a given member . This method encapsulates the error handling logic and the handling of accessibility of the member .