public static Object getValue ( Object object , Field field ) throws VisitorException { boolean reprotect = false ; if ( object == null ) { return null ; } try { if ( ! field . isAccessible ( ) ) { field . setAccessible ( true ) ; reprotect = true ; } Object value = field . get ( object ) ; logger . trace ( "field '{}' has value '{}'" , field . getName ( ) , value ) ; return value ; } catch ( IllegalArgumentException e ) { logger . error ( "Trying to access field '{}' on invalid object of class '{}'" , field . getName ( ) , object . getClass ( ) . getSimpleName ( ) ) ; throw new VisitorException ( "Trying to access field on invalid object" , e ) ; } catch ( IllegalAccessException e ) { logger . error ( "Illegal access to class '{}'" , object . getClass ( ) . getSimpleName ( ) ) ; throw new VisitorException ( "Illegal access to class" , e ) ; } finally { if ( reprotect ) { field . setAccessible ( false ) ; } } }
Returns the value of the given field on the given object .