Applet. java.lang.reflect.InvocationTargetException

I have an applet that uses the jna Pointer class. Applet code:

import com.sun.jna.*; public class Applet1 extends Applet{ public void test() { try { Pointer p = new Memory(73); } catch (Exception e) { e.printStackTrace(); } } } 

In the html code, I declared the applet as follows:

 <applet codebase=/pki/ code=Applet1.class archive=/pki/jna-3.2.3.jar id=Applet1 width=100 height=100 > </applet> 

When I call document.getElementById ("Applet1"). test () by javascript raises java.lang.reflect.InvocationTargetException. I cannot call e.getCause () in the java class because the try / catch applet will not catch the error (I don't understand why). But javascript try / catch caught this error. If you move the line Pointer p = new Memory(73); it will be ok. The point is this line. Please help fix the problem.

EDIT: if replacing this block:

 try { Pointer p = new Memory(73); } catch (Exception e) { e.printStackTrace(); } 

to

 try { Pointer p = new Memory(73); } catch (Throwable e) { System.out.println(e.getCause()); } 

I got java.security.AccessControlException: access denied (java.util.PropertyPermission jna.boot.library.path read)

+4
source share
1 answer

OK, now we are at the root of the problem. (You could still use printStackTrace - this should also print a trace of the cause stack.).

  • Unsigned applets have access only to a limited number of system properties - jna properties jna not part of these.

  • In an unsigned applet, you cannot load your own libraries anyway, therefore you cannot use JNA (or JNI, by the way).

  • If you sign the applet (and tell the plugin to accept the signature), your applet has the necessary rights to use JNA. But the rights to any one executable code effectively intersect the rights of all methods, which are called the current code.

    JavaScript applet methods have extremely limited permissions (since the plugin cannot really verify that the JavaScript code has the required permissions, even if your browser even has this concept).

    You can get around this by wrapping the part of the code that should be executed with your applet permissions with AccessController.doPrivileged(...) . But first, make sure that this cannot do anything dangerous (which is easy with JNI / JNA) even when invoked from malicious JavaScript code.

+7
source

All Articles