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

Animation and AnimationTimer methods must be called on JavaFX Application thread

    XMLWordPrintable

Details

    • b05
    • x86
    • other
    • Fix failed

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.10586]

      A DESCRIPTION OF THE PROBLEM :
      During each cycle in the AbstractMasterTimer it gives this exception

      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
      at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
      at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
      at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:521)
      at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:505)
      at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$400(QuantumToolkit.java:334)
      at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$40/559455589.run(Unknown Source)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
      at com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:745)

      After doing a bit more digging, I found out that this was as a result of a concurrent modification (might be a bad practice anyway) when multiple Animations were stopped (sequentially, the corresponding PulseReceiver is removed) and started at the same time (sequentially, the corresponding PulsReceiver is added). The array of receivers had a few Null-Pointer references as a result.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Take the source code of BugTest and compile (command: javac BugTest.java)

      2. Run the class file (command: java BugTest)


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      This should produce no error and no output.
      ACTUAL -
      The actual run produces a NullPointerException each time the AbstractMasterTimer cycles through one loop


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
              at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
              at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
              at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
              at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
              at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
              at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
              at java.lang.Thread.run(Unknown Source)
      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
              at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
              at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
              at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
              at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
              at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
              at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
              at java.lang.Thread.run(Unknown Source)
      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
              at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
              at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
              at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
              at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
              at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
              at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
              at java.lang.Thread.run(Unknown Source)
      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
              at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
              at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
              at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
              at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
              at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
              at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
              at java.lang.Thread.run(Unknown Source)
      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
              at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
              at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
              at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
              at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
              at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
              at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
              at java.lang.Thread.run(Unknown Source)
      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
              at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
              at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
              at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
              at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
              at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
              at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
              at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
              at java.lang.Thread.run(Unknown Source)

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      import javafx.animation.AnimationTimer;
      import javafx.application.Application;
      import javafx.stage.Stage;

      public class BugTest extends Application
      {
      public static void main(String[] args)
      {
      Application.launch(args);
      }

      @Override
      public void start(Stage primaryStage) throws Exception
      {
      for (int i = 0; i < 10; i++)
      // Some nasty concurrent mods?
      bugProc();
      }

      /*
      * This manifests the NullPointer bug issue.
      */
      private void bugProc()
      {

      Thread bugger = new Thread(() ->
      {
      AnimationTimer tester = new AnimationTimer()
      {

      @Override
      public void handle(long now)
      {
      waitSomeTime(10); // Some intensive processing
      }
      };

      while (true)
      {
      //Initialize the concurrent starts and stops
      tester.start();
      waitSomeTime(10);
      tester.stop();
      waitSomeTime(10);
      }
      });
      bugger.start();
      }

      /**
      * Utility method for waiting some time
      * @param millis time in milliseconds to wait
      */
      private static void waitSomeTime(long millis)
      {
      try
      {
      Thread.sleep(millis);
      }
      catch (InterruptedException e)
      {
      }
      }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Instead of using a different thread to start and stop the animation, wrap the start/stop animation code in a Platform.runLater(Runnable) so that all the actual start and stopping animation would occur in the JavaFX Application Thread.

      Attachments

        Issue Links

          Activity

            People

              jpereda Jose Pereda
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: