示例#1
0
 private void performSecure(Runnable runnable) {
   if (System.getSecurityManager() != null) {
     AccessController.doPrivileged(
         (PrivilegedAction<?>)
             () -> {
               runnable.run();
               return null;
             });
   } else {
     runnable.run();
   }
 }
示例#2
0
 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);
     }
   }
 }