[libbluray-devel] BDJSockets: reflection needs doPrivileged()

hpi1 git at videolan.org
Tue Mar 24 13:40:55 CET 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Mar 24 14:26:14 2015 +0200| [af68e613b0fe1fb7743df6fe9c536132d0a6fd01] | committer: hpi1

BDJSockets: reflection needs doPrivileged()

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

 .../bdj/java/org/videolan/BDJSockets.java          |   20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJSockets.java b/src/libbluray/bdj/java/org/videolan/BDJSockets.java
index 44673fc..81a25ba 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJSockets.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJSockets.java
@@ -24,6 +24,10 @@ import java.lang.reflect.Method;
 import java.util.Iterator;
 import java.util.LinkedList;
 
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
 import java.net.Socket;
 import java.net.SocketImpl;
 
@@ -73,11 +77,17 @@ class BDJSockets {
 
     private Socket getSocket(SocketImpl socketImpl) {
         try {
-            Method getSocket = SocketImpl.class.getDeclaredMethod("getSocket", new Class[0]);
-            getSocket.setAccessible(true);
-            return (Socket) getSocket.invoke(socketImpl, new Object[0]);
-        } catch (Exception e) {
-            logger.error("Failed to get Socket: " + e + " at " + Logger.dumpStack());
+            final SocketImpl si = socketImpl;
+            return (Socket)AccessController.doPrivileged(
+                new PrivilegedExceptionAction() {
+                    public Object run() throws Exception {
+                        Method getSocket = SocketImpl.class.getDeclaredMethod("getSocket", new Class[0]);
+                        getSocket.setAccessible(true);
+                        return getSocket.invoke(si, new Object[0]);
+                    }
+                });
+        } catch (PrivilegedActionException e) {
+            logger.error("Failed to get Socket: " + e.getException() + " at " + Logger.dumpStack());
             return null;
         }
     }



More information about the libbluray-devel mailing list