From c965bcf2b8cce8f81e2abc64b8960b653ddf5c00 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 15 Jan 2023 03:14:29 +0100 Subject: SecurityUtil: Skip System's SecurityManager action for getSecurityManager() and doPrivileged() for Java17+ --- src/java/com/jogamp/common/util/SecurityUtil.java | 38 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/java/com/jogamp/common/util/SecurityUtil.java') diff --git a/src/java/com/jogamp/common/util/SecurityUtil.java b/src/java/com/jogamp/common/util/SecurityUtil.java index 9591f70..6d5b639 100644 --- a/src/java/com/jogamp/common/util/SecurityUtil.java +++ b/src/java/com/jogamp/common/util/SecurityUtil.java @@ -34,6 +34,8 @@ import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.security.cert.Certificate; +import jogamp.common.os.PlatformPropsImpl; + public class SecurityUtil { @SuppressWarnings("removal") private static final SecurityManager securityManager; @@ -41,22 +43,44 @@ public class SecurityUtil { private static final boolean DEBUG = false; /** - * Deprecated call to {@link System#getSecurityManager()} w/o warnings. + * Call wrapper for {@link System#getSecurityManager()}. + *

+ * {@link System#getSecurityManager()} is deprecated + * since Java 17 (JEP 411) and earmarked to be removed.
+ *

+ *

+ * On a Java 17 machine, this method will simply return null. + *

*/ @SuppressWarnings({ "deprecation", "removal" }) public static final SecurityManager getSecurityManager() { - return System.getSecurityManager(); + if( PlatformPropsImpl.JAVA_17 ) { + return null; + } else { + return System.getSecurityManager(); + } } /** - * Deprecated call to {@link java.security.AccessController#doPrivileged(PrivilegedAction)} w/o warnings. - * @param - * @param o - * @return + * Call wrapper for {@link java.security.AccessController#doPrivileged(PrivilegedAction)}. + *

+ * {@link java.security.AccessController#doPrivileged(PrivilegedAction)} is deprecated + * since Java 17 (JEP 411) and earmarked to be removed.
+ *

+ *

+ * On a Java 17 machine, this method will simply invoke the given PrivilegedAction. + *

+ * @param return type of PrivilegedAction + * @param o the PrivilegedAction + * @return the return type */ @SuppressWarnings({ "deprecation", "removal" }) public static T doPrivileged(final PrivilegedAction o) { - return java.security.AccessController.doPrivileged( o ); + if( PlatformPropsImpl.JAVA_17 ) { + return o.run(); + } else { + return java.security.AccessController.doPrivileged( o ); + } } static { -- cgit v1.2.3