--- old/src/macosx/classes/sun/lwawt/LWWindowPeer.java 2013-09-04 12:42:13.408343000 +0400 +++ new/src/macosx/classes/sun/lwawt/LWWindowPeer.java 2013-09-04 12:42:13.236742700 +0400 @@ -81,9 +81,10 @@ // check that the mouse is over the window private volatile boolean isMouseOver = false; + private static final Object lastCommonMouseEventPeerLock = new Object(); // A peer where the last mouse event came to. Used by cursor manager to // find the component under cursor - private static volatile LWComponentPeer lastCommonMouseEventPeer = null; + private static LWComponentPeer lastCommonMouseEventPeer = null; // A peer where the last mouse event came to. Used to generate // MOUSE_ENTERED/EXITED notifications @@ -710,9 +711,7 @@ // Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched // to a peer from another window. So we must first check if this peer is // the same as lastWindowPeer - if (lastCommonMouseEventPeer != null && lastCommonMouseEventPeer.getWindowPeerOrSelf() == this) { - lastCommonMouseEventPeer = null; - } + cleanLastCommonMouseEventPeer(this); lastMouseEventPeer = null; } } else if(id == MouseEvent.MOUSE_ENTERED) { @@ -724,7 +723,7 @@ postMouseEnteredEvent(target, when, modifiers, lp, screenX, screenY, clickCount, popupTrigger, button); } - lastCommonMouseEventPeer = targetPeer; + setLastCommonMouseEventPeer(targetPeer); lastMouseEventPeer = targetPeer; } } else { @@ -853,7 +852,7 @@ postMouseExitedEvent(target, when, modifiers, oldp, screenX, screenY, clickCount, popupTrigger, button); } - lastCommonMouseEventPeer = targetPeer; + setLastCommonMouseEventPeer(targetPeer); lastMouseEventPeer = targetPeer; // Generate Mouse Enter for components @@ -1111,11 +1110,31 @@ } public static LWWindowPeer getWindowUnderCursor() { - return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null; + synchronized (lastCommonMouseEventPeerLock) { + return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null; + } } public static LWComponentPeer getPeerUnderCursor() { - return lastCommonMouseEventPeer; + synchronized (lastCommonMouseEventPeerLock) { + return lastCommonMouseEventPeer; + } + } + + static boolean cleanLastCommonMouseEventPeer(LWWindowPeer previous) { + synchronized (lastCommonMouseEventPeerLock) { + if (lastCommonMouseEventPeer != null && lastCommonMouseEventPeer.getWindowPeerOrSelf() == previous) { + lastCommonMouseEventPeer = null; + return true; + } + return false; + } + } + + static void setLastCommonMouseEventPeer(LWComponentPeer newValue) { + synchronized (lastCommonMouseEventPeerLock) { + lastCommonMouseEventPeer = newValue; + } } /*