package org.ringojs.wrappers;

import org.ringojs.util.POSIXSupport;

/**
 * A wrapper class to allow retrieving jnr-posix support while protecting
 * the caller against NoClassDefFoundError if jnr-posix support is not installed.
 */
public class POSIX {

    public static Object getPOSIX() throws ClassNotFoundException {
        try {
            return POSIXSupport.getPOSIX();
        } catch (NoClassDefFoundError noclass) {
            throw new ClassNotFoundException(noclass.getMessage(), noclass);
        }
    }
}

@@ -63,16 +63,95 @@
 pport;%0A%0A
+import java.security.AccessController;%0Aimport java.security.PrivilegedAction;%0A%0A
 /**%0A * A
@@ -408,58 +408,371 @@
     
-try %7B%0A            return POSIXSupport.getPOSIX();%0A
+return AccessController.doPrivileged(new PrivilegedAction%3CObject%3E() %7B%0A            public Object run() %7B%0A                try %7B%0A                    org.jruby.ext.posix.POSIX posix = POSIXSupport.getPOSIX();%0A                    // call some method to make sure native library gets loaded%0A                    posix.getuid();%0A                    return posix;%0A        
     
@@ -828,16 +828,24 @@
         
+      
+  
 throw ne
@@ -846,29 +846,23 @@
 row new 
-ClassNotFound
+Runtime
 Exceptio
@@ -874,32 +874,42 @@
 lass
-.getMessage(), noclass);
+);%0A                %7D%0A            %7D
 %0A   
@@ -910,21 +910,23 @@
  %7D%0A        %7D
+);
 %0A    %7D%0A%7D%0A

Make sure native POSIX library gets loaded in privileged action.