Issue
JDK11 has removed checkSystemClipboardAccess
from SecurityManager
. What's the suggested alternative idiom in Clipboard handling?
I wanted to check Clipboard availability like this:
public static boolean hasClipboard() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) return true;
try {
sm.checkSystemClipboardAccess();
return true;
} catch (SecurityException x) {
/* */
}
return false;
}
But its impossible to compile it in JDK11.
Edit 01.02.2020:
Based on suggestions I am now using:
public static boolean hasClipboard() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) return true;
try {
sm.checkPermission(new AWTPermission("accessClipboard"));
return true;
} catch (SecurityException x) {
/* */
}
return false;
}
Solution
A [Google] search for the terms java checkSystemClipboardAccess removed provided a link to Oracle's javadoc for class SecurityManager
(JDK 10), and the documentation for method checkSystemClipboardAccess() contains the following:
Deprecated, for removal: This API element is subject to removal in a future version. This method was originally used to check if the calling thread could access the system clipboard. The method has been obsoleted and code should instead use checkPermission(java.security.Permission) to check AWTPermission("accessClipboard"). This method is subject to removal in a future version of Java SE.
Answered By - Abra
Answer Checked By - Cary Denson (JavaFixing Admin)