You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2013/12/18 16:58:08 UTC

svn commit: r1551992 - /pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java

Author: rwhitcomb
Date: Wed Dec 18 15:58:08 2013
New Revision: 1551992

URL: http://svn.apache.org/r1551992
Log:
PIVOT-927:  Seemingly random occurrence of a NullPointerException during
mouse operations causes the UI thread to crash, making the application
unresponsive.

>From the stack trace the problem is a null location for the mouse which
is not checked before referencing the location variable.

So, protect all references to the location with a null check first.  Also
make some effort to use the display mouse location if necessary (that is,
if the "mapPointFromAncestor" returns a null location).

Modified:
    pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java

Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=1551992&r1=1551991&r2=1551992&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Wed Dec 18 15:58:08 2013
@@ -178,9 +178,14 @@ public abstract class ApplicationContext
 
                         Point dropLocation = dropDescendant.mapPointFromAncestor(display,
                             location.x, location.y);
-                        dropAction = dropTarget.dragMove(dropDescendant, dragManifest,
-                            getSupportedDropActions(event.getSourceActions()),
-                            dropLocation.x, dropLocation.y, userDropAction);
+                        if (dropLocation == null) {
+                            dropLocation = display.getMouseLocation();
+                        }
+                        if (dropLocation != null) {
+                            dropAction = dropTarget.dragMove(dropDescendant, dragManifest,
+                                getSupportedDropActions(event.getSourceActions()),
+                                dropLocation.x, dropLocation.y, userDropAction);
+                        }
                     }
                 } else {
                     if (previousDropDescendant != null) {
@@ -218,11 +223,16 @@ public abstract class ApplicationContext
                     java.awt.Point location = event.getLocation();
                     Point dropLocation = dropDescendant.mapPointFromAncestor(display,
                         location.x, location.y);
+                    if (dropLocation == null) {
+                        dropLocation = display.getMouseLocation();
+                    }
 
-                    DropTarget dropTarget = dropDescendant.getDropTarget();
-                    dropAction = dropTarget.userDropActionChange(dropDescendant, dragManifest,
-                        getSupportedDropActions(event.getSourceActions()), dropLocation.x, dropLocation.y,
-                        userDropAction);
+                    if (dropLocation != null) {
+                        DropTarget dropTarget = dropDescendant.getDropTarget();
+                        dropAction = dropTarget.userDropActionChange(dropDescendant, dragManifest,
+                            getSupportedDropActions(event.getSourceActions()),
+                            dropLocation.x, dropLocation.y, userDropAction);
+                    }
                 }
 
                 if (dropAction == null) {
@@ -244,13 +254,19 @@ public abstract class ApplicationContext
                 if (dropDescendant != null) {
                     Point dropLocation = dropDescendant.mapPointFromAncestor(display,
                         location.x, location.y);
+                    if (dropLocation == null) {
+                        dropLocation = display.getMouseLocation();
+                    }
+
                     DropTarget dropTarget = dropDescendant.getDropTarget();
 
                     // Simulate a user drop action change to get the current drop action
                     int supportedDropActions = getSupportedDropActions(event.getSourceActions());
 
-                    dropAction = dropTarget.userDropActionChange(dropDescendant, dragManifest,
-                        supportedDropActions, dropLocation.x, dropLocation.y, userDropAction);
+                    if (dropLocation != null) {
+                        dropAction = dropTarget.userDropActionChange(dropDescendant, dragManifest,
+                            supportedDropActions, dropLocation.x, dropLocation.y, userDropAction);
+                    }
 
                     if (dropAction != null) {
                         // Perform the drop
@@ -932,8 +948,13 @@ public abstract class ApplicationContext
                 } else {
                     mouseOwner = mouseCapturer;
                     Point location = mouseOwner.mapPointFromAncestor(display, x, y);
-                    x = location.x;
-                    y = location.y;
+                    if (location == null) {
+                        location = display.getMouseLocation();
+                    }
+                    if (location != null) {
+                        x = location.x;
+                        y = location.y;
+                    }
                 }
 
                 // Delegate the event to the owner
@@ -1111,53 +1132,64 @@ public abstract class ApplicationContext
                                     } else {
                                         DragSource dragSource = dragDescendant.getDragSource();
                                         dragLocation = dragDescendant.mapPointFromAncestor(display, x, y);
+                                        if (dragLocation == null) {
+                                            dragLocation = display.getMouseLocation();
+                                        }
 
-                                        if (dragSource.beginDrag(dragDescendant,
-                                            dragLocation.x, dragLocation.y)) {
-                                            // A drag has started
-                                            if (dragSource.isNative()) {
-                                                startNativeDrag(dragSource, dragDescendant,
-                                                    event);
-
-                                                // Clear the drag state since it is not used for
-                                                // native drags
+                                        if (dragLocation != null) {
+                                            if (dragSource.beginDrag(dragDescendant,
+                                                dragLocation.x, dragLocation.y)) {
+                                                // A drag has started
+                                                if (dragSource.isNative()) {
+                                                    startNativeDrag(dragSource, dragDescendant,
+                                                        event);
+
+                                                    // Clear the drag state since it is not used for
+                                                    // native drags
+                                                    dragDescendant = null;
+                                                    dragLocation = null;
+                                                } else {
+                                                    if (dragSource.getRepresentation() != null
+                                                        && dragSource.getOffset() == null) {
+                                                        throw new IllegalStateException("Drag offset is required when a "
+                                                            + "representation is specified.");
+                                                    }
+
+                                                    if (display.isMouseOver()) {
+                                                        display.mouseOut();
+                                                    }
+
+                                                    // Get the drag content
+                                                    dragManifest = dragSource.getContent();
+
+                                                    // Get the initial user drop action
+                                                    userDropAction = getUserDropAction(event);
+
+                                                    // Repaint the drag visual
+                                                    dragLocation = new Point(x, y);
+                                                    repaintDragRepresentation();
+                                                }
+                                            } else {
+                                                // Clear the drag state
                                                 dragDescendant = null;
                                                 dragLocation = null;
-                                            } else {
-                                                if (dragSource.getRepresentation() != null
-                                                    && dragSource.getOffset() == null) {
-                                                    throw new IllegalStateException("Drag offset is required when a "
-                                                        + " representation is specified.");
-                                                }
-
-                                                if (display.isMouseOver()) {
-                                                    display.mouseOut();
-                                                }
-
-                                                // Get the drag content
-                                                dragManifest = dragSource.getContent();
-
-                                                // Get the initial user drop action
-                                                userDropAction = getUserDropAction(event);
-
-                                                // Repaint the drag visual
-                                                dragLocation = new Point(x, y);
-                                                repaintDragRepresentation();
                                             }
-                                        } else {
-                                            // Clear the drag state
-                                            dragDescendant = null;
-                                            dragLocation = null;
                                         }
                                     }
                                 }
                             } else {
                                 // Delegate the event to the capturer
                                 Point location = mouseCapturer.mapPointFromAncestor(display, x, y);
-                                boolean consumed = mouseCapturer.mouseMove(location.x, location.y);
+                                if (location == null) {
+                                    location = display.getMouseLocation();
+                                }
 
-                                if (consumed) {
-                                    event.consume();
+                                if (location != null) {
+                                    boolean consumed = mouseCapturer.mouseMove(location.x, location.y);
+
+                                    if (consumed) {
+                                        event.consume();
+                                    }
                                 }
                             }
                         } else {
@@ -1176,9 +1208,14 @@ public abstract class ApplicationContext
                                         DropTarget dropTarget = dropDescendant.getDropTarget();
 
                                         Point dropLocation = dropDescendant.mapPointFromAncestor(display, x, y);
-                                        dropAction = dropTarget.dragMove(dropDescendant, dragManifest,
-                                            dragSource.getSupportedDropActions(),
-                                            dropLocation.x, dropLocation.y, userDropAction);
+                                        if (dropLocation == null) {
+                                            dropLocation = display.getMouseLocation();
+                                        }
+                                        if (dropLocation != null) {
+                                            dropAction = dropTarget.dragMove(dropDescendant, dragManifest,
+                                                dragSource.getSupportedDropActions(),
+                                                dropLocation.x, dropLocation.y, userDropAction);
+                                        }
                                     }
                                 } else {
                                     if (previousDropDescendant != null) {
@@ -1263,8 +1300,13 @@ public abstract class ApplicationContext
                             } else {
                                 mouseOwner = mouseCapturer;
                                 Point location = mouseOwner.mapPointFromAncestor(display, x, y);
-                                x = location.x;
-                                y = location.y;
+                                if (location == null) {
+                                    location = display.getMouseLocation();
+                                }
+                                if (location != null) {
+                                    x = location.x;
+                                    y = location.y;
+                                }
                             }
 
                             // Delegate the event to the owner
@@ -1468,15 +1510,18 @@ public abstract class ApplicationContext
                         DropTarget dropTarget = dropDescendant.getDropTarget();
 
                         Point dropLocation = dragLocation;
+                        if (dropLocation != null) {
+                            dropLocation = dropDescendant.mapPointFromAncestor(display,
+                                dropLocation.x, dropLocation.y);
+                        }
                         if (dropLocation == null) {
                             dropLocation = display.getMouseLocation();
                         }
-
-                        dropLocation = dropDescendant.mapPointFromAncestor(display,
-                            dropLocation.x, dropLocation.y);
-                        dropTarget.userDropActionChange(dropDescendant, dragManifest,
-                            dragSource.getSupportedDropActions(),
-                            dropLocation.x, dropLocation.y, userDropAction);
+                        if (dropLocation != null) {
+                            dropTarget.userDropActionChange(dropDescendant, dragManifest,
+                                dragSource.getSupportedDropActions(),
+                                dropLocation.x, dropLocation.y, userDropAction);
+                        }
                     }
                 }
             }