From 7312c3822cd8538df108279b22e122a3c50032f7 Mon Sep 17 00:00:00 2001
From: Kenneth Russel <kbrussel@alum.mit.edu>
Date: Fri, 22 Dec 2006 00:35:57 +0000
Subject: Fixed latent problem with lookup of native libraries using
 ClassLoader

git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/gluegen/trunk@54 a78bb65f-1512-4460-ba86-f6dc96a7bf27
---
 src/java/com/sun/gluegen/runtime/NativeLibrary.java | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

(limited to 'src/java/com')

diff --git a/src/java/com/sun/gluegen/runtime/NativeLibrary.java b/src/java/com/sun/gluegen/runtime/NativeLibrary.java
index 8ff28d3..9b28da4 100755
--- a/src/java/com/sun/gluegen/runtime/NativeLibrary.java
+++ b/src/java/com/sun/gluegen/runtime/NativeLibrary.java
@@ -241,6 +241,9 @@ public class NativeLibrary {
     // The idea to ask the ClassLoader to find the library is borrowed
     // from the LWJGL library
     String clPath = getPathFromClassLoader(libName, loader);
+    if (DEBUG) {
+      System.out.println("Class loader path to " + libName + ": " + clPath);
+    }
     if (clPath != null) {
       paths.add(clPath);
     }
@@ -321,7 +324,7 @@ public class NativeLibrary {
 
   private static boolean initializedFindLibraryMethod = false;
   private static Method  findLibraryMethod = null;
-  private static String getPathFromClassLoader(final String libName, ClassLoader loader) {
+  private static String getPathFromClassLoader(final String libName, final ClassLoader loader) {
     if (loader == null)
       return null;
     if (!initializedFindLibraryMethod) {
@@ -341,8 +344,19 @@ public class NativeLibrary {
     }
     if (findLibraryMethod != null) {
       try {
-        return (String) findLibraryMethod.invoke(loader, new Object[] { libName });
+        return (String) AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+              try {
+                return findLibraryMethod.invoke(loader, new Object[] { libName });
+              } catch (Exception e) {
+                throw new RuntimeException(e);
+              }
+            }
+          });
       } catch (Exception e) {
+        if (DEBUG) {
+          e.printStackTrace();
+        }
         // Fail silently and continue with other search algorithms
       }
     }
-- 
cgit v1.2.3