[英]Null Pointer Exception when calling java.awt.Toolkit.getDefaultToolkit() from OS X Applet
I'm getting the following NPE when trying to view a Java applet on OS X 10.7.5: 尝试在OS X 10.7.5上查看Java小程序时,出现以下NPE:
[2014-04-07T11:39:22.035] [thread applet-com.OTHERCOMPANY.wave.applets.PRODUCT.PRODUCT.class-2] com.COMPANY.nm.logging.LogMaster.auditLoggingMessage AUDIT: HEMXL0001A=Audit logging is enabled.
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at com.COMPANY.XYZ.applets.PRODUCT.ui.table.TableMouseListener.<init>(TableMouseListener.java:71)
at com.COMPANY.XYZ.applets.PRODUCT.PRODUCTTable.<init>(PRODUCTTable.java:315)
I do not have the source but assume to have found TableMouseListener.java:71 using javap: 我没有源,但假设使用javap找到了TableMouseListener.java:71:
public com.COMPANY.XYZ.applets.PRODUCT.ui.table.TableMouseListener(com.COMPANY.XYZ.applets.PRODUCT.PRODUCTContext, javax.swing.JTable);
flags: ACC_PUBLIC
Code:
stack=5, locals=4, args_size=3
0: aload_0
1: invokespecial #1 // Method com/OTHERCOMPANY/wave/uicomponents/PopupListener."<init>":()V
4: aload_0
5: aconst_null
6: putfield #2 // Field firstClickEvent:Ljava/awt/event/MouseEvent;
9: aload_0
10: aload_1
11: putfield #3 // Field context:Lcom/COMPANY/XYZ/applets/PRODUCT/PRODUCTContext;
14: aload_0
15: aload_2
16: putfield #4 // Field table:Ljavax/swing/JTable;
THIS --->
19: invokestatic #5 // Method java/awt/Toolkit.getDefaultToolkit:()Ljava/awt/Toolkit;
22: ldc #6 // String awt.multiClickInterval
24: invokevirtual #7 // Method java/awt/Toolkit.getDesktopProperty:(Ljava/lang/String;)Ljava/lang/Object;
27: checkcast #8 // class java/lang/Integer
30: invokevirtual #9 // Method java/lang/Integer.intValue:()I
33: istore_3
34: aload_0
THIS --->
35: new #10 // class javax/swing/Timer
38: dup
39: iload_3
40: aload_0
41: invokespecial #11 // Method javax/swing/Timer."<init>":(ILjava/awt/event/ActionListener;)V
44: putfield #12 // Field clickTimer:Ljavax/swing/Timer;
47: return
LineNumberTable:
line 65: 0
line 62: 4
line 66: 9
line 67: 14
line 71: 19
line 72: 34
line 73: 47
Any good ideas what might cause this and what could be a workaround? 有什么好主意可能会导致这种情况,以及什么可以解决? I'm not exactly clear on what this toolkit does but it seems to provide an interface to the graphics system which might be restricted from the applet sandbox? 我不清楚这个工具包的功能,但似乎提供了图形系统的接口,该接口可能会受到applet沙箱的限制?
Some stuff I have investigated: 我调查了一些东西:
$ cat gettk.java import java.awt.*; public class gettk { public static void main(String args[]) throws Exception { System.out.println("tk = " + Toolkit.getDefaultToolkit()); } } $ java gettk tk = sun.lwawt.macosx.LWCToolkit@32d16dc8
Update I: as suggested by a comment, here's a nicer decompile. 更新I:如评论所建议,这是一个更好的反编译。 Line 71 is: 第71行是:
int multiClickInterval = ((Integer)Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")).intValue();
Turns out the problem might very well be the usage of awt.multiClickInterval. 原来问题很可能是awt.multiClickInterval的用法。 I'll check if I can shoehorn this in from <embed>
properties. 我将检查是否可以通过<embed>
属性对此进行处理。
Update II: 更新二:
Yes the missing awt.multiClickInterval
is the issue: 是的,缺少awt.multiClickInterval
是问题所在:
rc@ds9000:~ $ cat gettk.java
import java.awt.*;
public class gettk {
public static void main(String args[]) throws Exception {
System.out.println("tk = " + Toolkit.getDefaultToolkit());
int multiClickInterval = ((Integer)Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")).intValue();
System.out.println(multiClickInterval);
}
}
rc@ds9000:~ $ java gettk
tk = sun.lwawt.macosx.LWCToolkit@15e6e48b
Exception in thread "main" java.lang.NullPointerException
at gettk.main(gettk.java:6)
Unfortunately I seem to be unable to pass it as system property: 不幸的是,我似乎无法将其作为系统属性传递:
rc@ds9000:~ $ java -Dawt.multiClickInterval=200 gettk
tk = sun.lwawt.macosx.LWCToolkit@15e6e48b
Exception in thread "main" java.lang.NullPointerException
at gettk.main(gettk.java:6)
Wierdly enough there is a note on how this was fixed in OS X 10.5 here (by Apple?), but also multiple instances of WONTFIX for Java 7 and 8 in the upstream JDK Jira here . 足够奇怪的是,这里有一个关于如何在OS X 10.5中 (由Apple修复)的注释,在此处还有上游JDK Jira中针对Java 7和8的WONTFIX的多个实例 。
Aha. 啊哈。 I found a fix for you. 我为您找到了解决方法。 It requires some hacks though. 但是它需要一些技巧。
public class HackApplet extends WhateverRandomAppletClassItWas {
public void init(){
Toolkit.getDefaultToolkit().setDesktopProperty("awt.multiClickInterval", 200);
super.init();
}
}
Then just get rid of the actual applet's signature (if any), add you custom applet in, manually sign (otherwise I'm sure setDesktopProperty
isn't going to work), and it should work. 然后,除去实际的applet签名(如果有的话),添加自定义applet,手动签名(否则,我确定setDesktopProperty
无法正常工作),它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.