小程序。 java.lang.reflect.InvocationTargetException

编程入门 行业动态 更新时间:2024-10-24 11:21:22
本文介绍了小程序。 java.lang.reflect.InvocationTargetException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有小程序使用JNA指针类。小程序code是:

进口com.sun.jna *。公共类Applet1扩展的Applet {    公共无效测试(){        尝试{            指针p =新的内存(73);        }赶上(例外五){        e.printStackTrace();        }    }}

在HTML code我宣布小程序是这样的:

<小程序    codeBase的= / PKI /    code = Applet1.class    存档= / PKI / JNA-3.2.3.jar    ID = Applet1    宽度= 100    高度= 100〕< /小程序>

当我打电话的document.getElementById(Applet1)。试验(+)由JavaScript的java.lang.reflect.InvocationTargetException出现。我不能叫e.getCause()将Java类方面,由于小应用程序的try / catch不捕获的错误(我不明白为什么)。但JavaScript的try / catch语句捕获此错误。如果移动指针p =新的内存(73); 行这将是确定。这个问题是此行。请帮助解决这个问题。

编辑:如果更换此块:

{尝试    指针p =新的内存(73);}赶上(例外五){    e.printStackTrace();}

{尝试    指针p =新的内存(73);}赶上(Throwable的E){    的System.out.println(e.getCause());}

我java.security.AccessControlException:访问被拒绝(java.util.PropertyPermission jna.boot.library.path读)

解决方案

好了,现在我们来到了问题的根源。 (您仍然可以使用了的printStackTrace - 这应该已打印的堆栈跟踪事业,也。)

  • 未签名的Applet只有系统属性数量有限的访问 - 在 JNA 属性不是这些部分

  • 在一个未签名的Applet无法加载本地库反正,所以没有办法用JNA(或JNI,顺便说一句)。

  • 如果您签名Applet(并告诉插件接受签名),您的小程序必须使用JNA的必要权限。但是,任何单个运行code的权利是有效的,要求当前code所有方法的权限的交集。

    Applet的方法从JavaScript叫有极其有限的权限(因为插件不能真正检查的JavaScript code具有必要的权限,如果你的浏览器,甚至有这样一个概念)。

    您可以去解决这个通过包装code,它需要与你的小程序的权限运行,以在AccessController.doPrivileged(...)部分。但首先确保这个不能做任何危险的(这是很容易用JNI / JNA),由恶意的JavaScript code叫时也是如此。

  • I have applet which use jna Pointer class. The applet code is:

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

    In html code I declared applet this way:

    <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 the java.lang.reflect.InvocationTargetException arise. I cant call e.getCause() in the java class side, because applet try/catch dont catch the error (I dont understand why). But javascript try/catch catch this error. If move Pointer p = new Memory(73); line it will be ok. The matter is this line. Please, help to fix the problem.

    EDIT: if replace 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)

    解决方案

    Okay, now we come to the root of the problem. (You still could have used printStackTrace - this should have printed the stack trace of the cause, too.).

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

  • In an unsigned applet you can't load native libraries anyways, so no way to 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 of any single running code is effectively the intersection of the rights of all methods which called the current code.

    Applet methods called from JavaScript have extremely limited permissions (since the Plugin can't really check that the JavaScript code has the necessary permissions, if your browser even has such a concept).

    You can go around this by wrapping the part of the code, which needs to run with your applet's permissions, with AccessController.doPrivileged(...). But first make sure this can't do anything dangerous (which is easy with JNI/JNA), even when called from malicious JavaScript code.

  • 更多推荐

    小程序。 java.lang.reflect.InvocationTargetException

    本文发布于:2023-10-28 23:35:06,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1538092.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:程序   java   lang   reflect   InvocationTargetException

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!