private void performSecure(Runnable runnable) { if (System.getSecurityManager() != null) { AccessController.doPrivileged( (PrivilegedAction<?>) () -> { runnable.run(); return null; }); } else { runnable.run(); } }
private <T> T performSecureGet(Callable<T> runnable) { if (System.getSecurityManager() != null) { return AccessController.doPrivileged( (PrivilegedAction<T>) () -> { try { return runnable.call(); } catch (Exception e) { throw new ReflectionException(e); } }); } else { try { return runnable.call(); } catch (Exception e) { throw new ReflectionException(e); } } }