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

NullPointerException in TabPaneSkin.stopDrag

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: openjfx13
    • Fix Version/s: openjfx14
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      When TabPaneSkin.stopDrag is entered without a prior call to startDrag, it will fail with an NPE, because dragTabHeader will be null.

      This situation can occur, when a mouse pressed event is consumed by another window (e.g. a popup) but the mouse released event is then already sent to the tab pane.

      This minimal example demonstrates the problem:
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.control.TabPane.TabDragPolicy;
      import javafx.scene.text.Text;
      import javafx.stage.Popup;
      import javafx.stage.Stage;

      public class TabPaneNPE extends Application {

      private Popup popup;

      @Override
      public void start(Stage stage) throws Exception {
      stage.setTitle("Demo showing NPE in TabPaneSkin");

      popup = new Popup();
      popup.setAutoHide(true);
      popup.getContent().add(new Text("Now click on the hobbit tab ..."));

      TabPane tabPane = new TabPane();
      tabPane.setTabDragPolicy(TabDragPolicy.REORDER);

      Tab elves = new Tab("Elves");
      Button content = new Button("click me");
      content.setOnMouseClicked(e -> {
      popup.show(stage);
      popup.requestFocus();
      });
      elves.setContent(content);
      tabPane.getTabs().add(elves);

      tabPane.getTabs().add(new Tab("Hobbits"));

      Scene scene = new Scene(tabPane, 640, 480);
      stage.setScene(scene);
      stage.show();
      }

      public static void main(String[] args) {
      launch();
      }
      }

      When you click on the "click me" button and then on the "Hobbits" tab you get:
      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
      at javafx.controls/javafx.scene.control.skin.TabPaneSkin.stopDrag(TabPaneSkin.java:2216)
      at javafx.controls/javafx.scene.control.skin.TabPaneSkin.handleHeaderMouseReleased(TabPaneSkin.java:2044)
      at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
      at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3862)
      at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
      at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2590)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
      at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
      at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
      at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
      at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
      at java.base/java.lang.Thread.run(Thread.java:830)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rlichten Robert Lichtenberger
                Reporter:
                rlichten Robert Lichtenberger
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: