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

NullPointerException in PickResultChooser.processOffer when using viewOrder

XMLWordPrintable

    • x86_64
    • windows

        ADDITIONAL SYSTEM INFORMATION :
        Windows 10.
        java version "10" 2018-03-20
        Java(TM) SE Runtime Environment 18.3 (build 10+46)
        Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

        A DESCRIPTION OF THE PROBLEM :
        Related to JDK-8197547. That ticket was closed due to not enough information. This ticket provides more info and source code to reproduce the problem.

        As you can see from the comments in the test program, there are two different changes that can prevent the error from occurring: (1) do not set the viewOrder property. (2) set mouseTransparent==true on the Line.

        Info on these two changes is provided to help narrow down the problem. It is not necessary to make BOTH of the changes to prevent the error -- either one will do it.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the test program provided. Click once. Move the mouse. Click again. The exception will occur.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        No NPE should occur.
        ACTUAL -
        Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
        at javafx.graphics/com.sun.javafx.scene.input.PickResultChooser.processOffer(PickResultChooser.java:185)
        at javafx.graphics/com.sun.javafx.scene.input.PickResultChooser.offer(PickResultChooser.java:143)
        at javafx.graphics/javafx.scene.Node.doComputeIntersects(Node.java:5238)
        at javafx.graphics/javafx.scene.Node.access$600(Node.java:398)
        at javafx.graphics/javafx.scene.Node$1.doComputeIntersects(Node.java:456)
        at javafx.graphics/com.sun.javafx.scene.NodeHelper.computeIntersectsImpl(NodeHelper.java:194)
        at javafx.graphics/com.sun.javafx.scene.NodeHelper.computeIntersects(NodeHelper.java:135)
        at javafx.graphics/javafx.scene.Node.intersects(Node.java:5209)
        at javafx.graphics/javafx.scene.Node.doPickNodeLocal(Node.java:5146)
        at javafx.graphics/javafx.scene.Node.access$500(Node.java:398)
        at javafx.graphics/javafx.scene.Node$1.doPickNodeLocal(Node.java:450)
        at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocalImpl(NodeHelper.java:189)
        at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocal(NodeHelper.java:130)
        at javafx.graphics/javafx.scene.Node.pickNode(Node.java:5178)
        at javafx.graphics/javafx.scene.Parent.pickChildrenNode(Parent.java:810)
        at javafx.graphics/javafx.scene.Parent$1.pickChildrenNode(Parent.java:143)
        at javafx.graphics/com.sun.javafx.scene.ParentHelper.pickChildrenNode(ParentHelper.java:120)
        at javafx.graphics/javafx.scene.layout.Region.doPickNodeLocal(Region.java:3162)
        at javafx.graphics/javafx.scene.layout.Region.access$600(Region.java:149)
        at javafx.graphics/javafx.scene.layout.Region$1.doPickNodeLocal(Region.java:186)
        at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.pickNodeLocalImpl(RegionHelper.java:104)
        at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocal(NodeHelper.java:130)
        at javafx.graphics/javafx.scene.Node.pickNode(Node.java:5178)
        at javafx.graphics/javafx.scene.Scene$MouseHandler.pickNode(Scene.java:4018)
        at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1400(Scene.java:3604)
        at javafx.graphics/javafx.scene.Scene.pick(Scene.java:2054)
        at javafx.graphics/javafx.scene.Scene.access$6900(Scene.java:173)
        at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3918)
        at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1300(Scene.java:3604)
        at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1874)
        at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2613)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
        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.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
        at java.base/java.lang.Thread.run(Thread.java:844)

        ---------- BEGIN SOURCE ----------
        import javafx.application.Application;
        import javafx.scene.Scene;
        import javafx.scene.input.MouseEvent;
        import javafx.scene.layout.Pane;
        import javafx.scene.paint.Color;
        import javafx.scene.shape.Line;
        import javafx.scene.shape.LineTo;
        import javafx.scene.shape.MoveTo;
        import javafx.scene.shape.Path;
        import javafx.stage.Stage;

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

            
            private Pane root;
            private Path path;
            private Line draftPathLine = null;
            
            
            @Override
            public void start( Stage primaryStage ) throws Exception {
                path = new Path();
                path.setViewOrder( 10 ); // remove this to fix exception
                
                root = new Pane();
                root.setPrefSize( 800, 600 );
                root.getChildren().add( path );
                root.setOnMouseClicked( this::onMouseClicked );
                root.setOnMouseMoved( this::onMouseMoved );

                var scene = new Scene( root, 800, 600 );

                primaryStage.setTitle( "Picking Exception Test" );
                primaryStage.setScene( scene );
                primaryStage.show();
            }

            private void onMouseClicked( MouseEvent evt ) {
                if (draftPathLine == null) {
                    double lineStartX = evt.getX();
                    double lineStartY = evt.getY();
                    if (!path.getElements().isEmpty()) {
                        var lastLineTo = (LineTo) path.getElements().get( path.getElements().size()-1 );
                        lineStartX = lastLineTo.getX();
                        lineStartY = lastLineTo.getY();
                    }
                    
                    draftPathLine = new Line( lineStartX, lineStartY, evt.getX(), evt.getY() );
                    draftPathLine.setStroke( Color.ORANGE );
                    draftPathLine.setMouseTransparent( false ); // mouseTransparent==true also fixes exception
                    root.getChildren().add( draftPathLine );
                } else {
                    if (path.getElements().isEmpty()) {
                        path.getElements().add( new MoveTo( draftPathLine.getStartX(), draftPathLine.getStartY() ) );
                    }
                    path.getElements().add( new LineTo( evt.getX(), evt.getY() ) );
                    root.getChildren().remove( draftPathLine );
                    draftPathLine = null;
                }
            }
            
            private void onMouseMoved( MouseEvent evt ) {
                if (draftPathLine != null) {
                    draftPathLine.setEndX( evt.getX() );
                    draftPathLine.setEndY( evt.getY() );
                }
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        The exception only occurs when viewOrder is set and the node is NOT mouse-transparent. It can be prevented by not using either of these conditions. However, that may be an insufficient workaround in many cases, because there may be compelling reasons why those conditions need to exist.

        FREQUENCY : always


              kcr Kevin Rushforth
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: