I'm getting the following NPE when trying to view a Java applet on OS X 10.7.5:
[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:
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?
Some stuff I have investigated:
- this did not happen with an older version of the applet that did not call getDefaultToolkit()
- this seems only to happen on OS X, Windows and Linux are fine
- I have tried the medium applet security setting, deleting the Java cache and some other voodoo to no avail
- Generally calling this method outside of an applet works fine, see below.
$ 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. Line 71 is:
int multiClickInterval = ((Integer)Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")).intValue();
Turns out the problem might very well be the usage of awt.multiClickInterval. I'll check if I can shoehorn this in from <embed>
properties.
Update II:
Yes the missing awt.multiClickInterval
is the issue:
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.
-Dawt.multiClickInterval=200
(or whatever your OS multi click interval is) – DankMemes