JDK-8143287 : SwingUtilities API call throws NPE with JRE 1.8.0_51
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2015-11-19
  • Updated: 2017-01-17
  • Resolved: 2016-02-10
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
After an application was upgraded from using 7u21 to using 8u51, there are many NullPointerException thrown.

On debugging, it was found SwingUtilities.<method_name> threw NPE over the RMI calls.

Following are some problem and stack traces:

1: Creating any Swing component in RMI thread throws NPE. In our application we create JRadioButton in RMI thread which throws the following exception:
Exception in thread "Thread-339" java.lang.NullPointerException
        at javax.swing.SwingUtilities.appContextGet(Unknown Source)
        at javax.swing.JComponent.getDefaultLocale(Unknown Source)
        at javax.swing.JComponent.<init>(Unknown Source)
        at javax.swing.AbstractButton.<init>(Unknown Source)

2:  On calling invokeLater(), invokeAndWait(), isEventDispatchThread() methods, RMI thread throws NPE.
These are the methods where we see the exception and there are other methods in SwingUtilities which throw NPE:
java.lang.NullPointerException
        at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source)
        at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source)
        at sun.awt.SunToolkit.getSystemEventQueueImpl(Unknown Source)

3: Appending text to JTextArea in RMI thread is throwing NPE:
java.lang.NullPointerException
        at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source)
        at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source)
        at sun.awt.SunToolkit.getSystemEventQueueImpl(Unknown Source)
        at java.awt.Toolkit.getEventQueue(Unknown Source)

Looks the issues persist since 7u25. Tried the same with latest JRE i.e. 8u65 but the issues persist there too.

JDK-8135232 looks similar and is unresolved in 8u45.

Using SwingRmiHelper.invokelater [1] instead of SwingUtilities.invokelater didn't help.

[1] http://www.oracle.com/technetwork/java/javase/7u51-relnotes-2085002.html
Area: deploy/webstart
Synopsis: Webstart applications that use RMI with SwingUtlities.invokeLater or invokeAndWait throw an NPE.
Comments
RMILogging.zip contains simple RMI server-client logging app. The server hosts JTextArea where messages sent from clients are added. In client, type a message into the text field and click Send or just press Enter to send the message to the server. There's command-line client which can be used for testing. The application consists of several jars: ��� common.jar - contains RemoteLogger interface declaration; ��� server.jar - contains Server implementation; ��� clientUI.jar - version of client with GUI; ��� client.jar - simple version of client with command-line interface. The provided server.jnlp and client.jnlp templates allow you to deploy the apps to a web server. Modify 'codebase' attribute of <jnlp> element to point to your web server. You can run JNLP apps using these commands: javaws http://your-web-server/path-to-jnlp-and-jars/server.jnlp javaws http://your-web-server/path-to-jnlp-and-jars/client.jnlp To start the app locally, as regular app, use these commands: java -jar server.jar java -jar clientUI.jar java -jar client.jar ["Message" ...] You can send several messages with client.jar. Running these jars requires common.jar to be in the same directory where server and client jars are located. To build the sample, just run ant. By default it executes 'jars' target which creates all the required jars. They will be put into build\jars directory.
17-01-2017

The behavior changed in 7u25 with JDK-8004584. NPE is fixed under JDK-8019274. Since SecurityManager is not set to null from application code in this case, JDK-8135232 does not apply.
17-02-2016

Upon further investigation, it was found the app works well in standalone mode, that is when run from command line or IDE. When the app is run via Web Start, NPE is thrown: java.lang.NullPointerException at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source) at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source) at sun.awt.SunToolkit.getSystemEventQueueImpl(Unknown Source) at java.awt.Toolkit.getEventQueue(Unknown Source) at java.awt.EventQueue.isDispatchThread(Unknown Source) at javax.swing.SwingUtilities.isEventDispatchThread(Unknown Source) at javax.swing.text.DefaultCaret$Handler.insertUpdate(Unknown Source) at javax.swing.text.AbstractDocument.fireInsertUpdate(Unknown Source) at javax.swing.text.AbstractDocument.handleInsertString(Unknown Source) at javax.swing.text.AbstractDocument.insertString(Unknown Source) at javax.swing.text.PlainDocument.insertString(Unknown Source) at javax.swing.JTextArea.append(Unknown Source) ��� at java.io.PrintStream.print(Unknown Source) at java.io.PrintStream.println(Unknown Source) ��� at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Unknown Source) at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source) ��� Usage scenario: We wrote our own console to print the log messages. We use JTextArea.append() method to print log messages to the console. We use System.setOut() to redirect all the standard output to this console. Logging occurs on the client side and is passed via RMI to server app hosting the console comprised of JTextArea. When we run the apps with Java Web Start, the exception above is thrown.
16-02-2016