JRE-359 CGraphicsEnvironment.getDefaultScreenDevice() returns null
Added privileged block for execution on AppKit
diff --git a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java b/src/macosx/classes/sun/awt/CGraphicsEnvironment.java
index 78c6454..93b5be2 100644
--- a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java
+++ b/src/macosx/classes/sun/awt/CGraphicsEnvironment.java
@@ -172,12 +172,15 @@
// of discrete video.
// So, we initialize the main display first, and then
// retrieve actual list of displays.
- final Callable<Integer> command = CGraphicsEnvironment::getMainDisplayID;
try {
- mainDisplayID = CThreading.executeOnAppKit(command);
- } catch (Throwable throwable) {
- throw new RuntimeException("Could not get main display ID");
+ mainDisplayID = CThreading.privilegedExecuteOnAppKit(
+ CGraphicsEnvironment::getMainDisplayID);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException("Could not get main display ID: " +
+ e.getMessage() );
}
createDevices();
@@ -193,13 +196,15 @@
if (!old.containsKey(mainDisplayID)) {
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID));
}
- final Callable<int[]> command = CGraphicsEnvironment::getDisplayIDs;
-
int[] displayIDs;
try {
- displayIDs = CThreading.executeOnAppKit(command);
- } catch (Throwable throwable) {
- throw new RuntimeException("Could not get main display IDs");
+ displayIDs = CThreading.privilegedExecuteOnAppKit(
+ CGraphicsEnvironment::getDisplayIDs);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException("Could not get display IDs: " +
+ e.getMessage());
}
for (final int id : displayIDs) {
diff --git a/src/macosx/classes/sun/lwawt/macosx/CThreading.java b/src/macosx/classes/sun/lwawt/macosx/CThreading.java
index 9928af0..d09304e 100644
--- a/src/macosx/classes/sun/lwawt/macosx/CThreading.java
+++ b/src/macosx/classes/sun/lwawt/macosx/CThreading.java
@@ -28,6 +28,8 @@
import java.awt.EventQueue;
import java.awt.AWTError;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
@@ -93,6 +95,28 @@
return command.call();
}
+ public static <V> V privilegedExecuteOnAppKit(Callable<V> command)
+ throws Exception {
+ try {
+ return java.security.AccessController.doPrivileged(
+ (PrivilegedExceptionAction<V>) () -> {
+ //noinspection TryWithIdenticalCatches
+ try {
+ return executeOnAppKit(command);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Error e) {
+ throw e;
+ } catch (Throwable throwable) {
+ throw new Exception(throwable);
+ }
+ }
+ );
+ } catch (PrivilegedActionException e) {
+ throw e.getException();
+ }
+ }
+
public static void executeOnAppKit(Runnable command) {
if (!isAppKit()) {
Dispatch dispatch = Dispatch.getInstance();