Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8019272

SwingUtilities.invokeLater(Runnable r) throws NullPointerexception from within

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version " 1.7.0_25 "
      Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
      Java HotSpot(TM) Server VM (build 23.25-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux pc002 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31 20:21:23 UTC 2013 (97c14ba) i686 athlon i386 GNU/Linux

      Windows XP, Windows 7

      A DESCRIPTION OF THE PROBLEM :
      SwingUtilities.invokeLater(Runnable r) throws NullPointerexception and SiwngUtilities.isEventDispatchThread() throws NPE too. That is because sun.awt.AppContext is null for some threads like thread created by RMI pool .

      It was working correctly on all previous JRE releases and JRE 1.7.0 Update 21, but I don't have such choice in the comboBox.

      REGRESSION. Last worked in version 5.0

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Build a RIA application that acts as a RMI server application (beside being a RMI client).
      1.1. Export some RMI Object with a method.
      2. Implement the method and use a SwingUtilities.invokeLater(..) within.
      3. Start the application with Java Web Start.
      4. Call the RMI Object with the method.
      5. JWS application will throw NullPointerException.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Normal functioning without throwing the exception. The same application executed without JWS work correctly.
      ACTUAL -
      -----------------
      Jun 25, 2013 1:55:47 PM AppletView$8 setBaseUnits
      INFO: AppContexts: [sun.awt.AppContext[threadGroup=main], sun.awt.AppContext[threadGroup=javawsApplicationThreadGroup], sun.awt.AppContext[threadGroup=javawsSecurityThreadGroup]]
      Jun 25, 2013 1:55:47 PM AppletView$8 setBaseUnits
      INFO: before invokeLater
      Exception in thread " AWT-EventQueue-2 " java.lang.NullPointerException
      at sun.awt.SunToolkit.getSystemEventQueueImplPP(SunToolkit.java:1011)
      at sun.awt.SunToolkit.getSystemEventQueueImplPP(SunToolkit.java:1007)
      at sun.awt.SunToolkit.getSystemEventQueueImpl(SunToolkit.java:1002)
      at java.awt.Toolkit.getEventQueue(Toolkit.java:1730)
      at java.awt.EventQueue.invokeLater(EventQueue.java:1217)
      at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1290)
      at AppletView$8.setBaseUnits(AppletView.java:560)
      -------------------------------


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      http://stackoverflow.com/questions/17223304/appcontext-is-null-from-rmi-thread-with-java-7-update-25?lq=1

      http://stackoverflow.com/questions/17275259/nullpointerexception-in-invokelater-while-running-through-java-webstart

      https://forums.oracle.com/message/11080621

      https://forums.oracle.com/thread/2552799

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      I am trying to write something brief. When I have some code I will attach it here by BugID or If I will attach it to the post in: (in case I will not have access to attach the test case).

      http://stackoverflow.com/questions/17275259/nullpointerexception-in-invokelater-while-running-through-java-webstart
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The application need to save the current AppContext in EVT:

        AppContext evtContext; //field

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                evtContext = AppContext.getAppContext();
            }
        });

      Then all the calls to SwingUtilities.invokeLater(..) from RMI threads must be replaced with custom invokeLater2(Runnable rn) method that uses sun.awt.SunToolkit.invokeLaterOnAppContext(..,..) like:

      void invokeLater2(Runnable rn) {
          if (AppContext.getAppContext() == null) {
              logger.warning( " AppContext is null, using EVT AppContext "
                + " through SunToolKit " );
              sun.awt.SunToolkit.invokeLaterOnAppContext(evtContext, rn);
          } else {
              SwingUtilities.invokeLater(rn);
          }
      }

      Unfortunately all the calls to SwingUtilities.invokeLater(..) from RMI threads must be replaced and the program now depends on internal Sun/Oracle JRE API.

            leonidr Leonid Romanov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: