private static AccessibleObject [ ] makeAccessible ( final AccessibleObject [ ] aoa ) { try { AccessibleObject . setAccessible ( aoa , true ) ; return aoa ; } catch ( Throwable outer ) { // swallow for strict security managers, module systems, android or others, // but try one-by-one to get the allowed ones at least final ArrayList < AccessibleObject > ret = new ArrayList <> ( aoa . length ) ; for ( final AccessibleObject ao : aoa ) { try { ao . setAccessible ( true ) ; ret . add ( ao ) ; } catch ( Throwable inner ) { // swallow for strict security managers, module systems, android or others } } return ret . toArray ( ( AccessibleObject [ ] ) Array . newInstance ( aoa . getClass ( ) . getComponentType ( ) , ret . size ( ) ) ) ; } }
to be run in PrivilegedAction!