[libbluray-devel] Use PrivilegedAction

hpi1 git at videolan.org
Wed Feb 25 14:33:14 CET 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Feb 25 15:02:01 2015 +0200| [7db78abda9c7954fb484618cf9eae635676385d9] | committer: hpi1

Use PrivilegedAction

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=7db78abda9c7954fb484618cf9eae635676385d9
---

 .../bdj/java-j2se/java/awt/peer/BDFramePeer.java        |   12 +++++++++++-
 src/libbluray/bdj/java/java/awt/BDImageBase.java        |   15 ++++++++++++---
 src/libbluray/bdj/java/java/io/BDFileSystem.java        |   14 +++++++++++++-
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/libbluray/bdj/java-j2se/java/awt/peer/BDFramePeer.java b/src/libbluray/bdj/java-j2se/java/awt/peer/BDFramePeer.java
index 7e7c0bb..b3d32d1 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/peer/BDFramePeer.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/peer/BDFramePeer.java
@@ -23,6 +23,9 @@ import java.awt.*;
 import java.awt.event.*;
 import java.awt.image.BufferedImage;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 import org.videolan.Logger;
 
 public class BDFramePeer extends BDComponentPeer implements FramePeer
@@ -174,7 +177,14 @@ public class BDFramePeer extends BDComponentPeer implements FramePeer
         if (c == null) {
             return true;
         }
-        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new FocusEvent(c, FocusEvent.FOCUS_GAINED));
+        final FocusEvent focusEvent = new FocusEvent(c, FocusEvent.FOCUS_GAINED);
+        AccessController.doPrivileged(
+            new PrivilegedAction() {
+                public Object run() {
+                    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(focusEvent);
+                    return null;
+                }
+            });
         return true;
     }
 
diff --git a/src/libbluray/bdj/java/java/awt/BDImageBase.java b/src/libbluray/bdj/java/java/awt/BDImageBase.java
index 0cf7b7f..5d52d08 100644
--- a/src/libbluray/bdj/java/java/awt/BDImageBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDImageBase.java
@@ -21,6 +21,8 @@ package java.awt;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Vector;
 import java.util.Enumeration;
 import java.awt.color.ColorSpace;
@@ -46,9 +48,16 @@ class BDImageBase extends Image {
 
     static {
         try {
-            Class c = Class.forName("java.awt.image.BufferedImage");
-            bufferedImageConstructor = c.getDeclaredConstructors()[0];
-            bufferedImageConstructor.setAccessible(true);
+            final Class c = Class.forName("java.awt.image.BufferedImage");
+            AccessController.doPrivileged(
+                new PrivilegedAction() {
+                    public Object run() {
+                        bufferedImageConstructor = c.getDeclaredConstructors()[0];
+                        bufferedImageConstructor.setAccessible(true);
+                        return null;
+                    }
+                }
+           );
         } catch (ClassNotFoundException e) {
             throw new AWTError("java.awt.image.BufferedImage not found");
         }
diff --git a/src/libbluray/bdj/java/java/io/BDFileSystem.java b/src/libbluray/bdj/java/java/io/BDFileSystem.java
index 9800022..7dd3dd1 100644
--- a/src/libbluray/bdj/java/java/io/BDFileSystem.java
+++ b/src/libbluray/bdj/java/java/io/BDFileSystem.java
@@ -31,6 +31,8 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import org.videolan.BDJLoader;
 import org.videolan.BDJXletContext;
@@ -42,7 +44,17 @@ public abstract class BDFileSystem extends FileSystem {
 
     protected final FileSystem fs;
 
-    public static void init(Class c) {
+    public static void init(final Class c) {
+        AccessController.doPrivileged(
+            new PrivilegedAction() {
+                public Object run() {
+                    init0(c);
+                    return null;
+                }
+            });
+    }
+
+    private static void init0(Class c) {
         Field filesystem;
         try {
             filesystem = c.getDeclaredField("fs");



More information about the libbluray-devel mailing list