JRE-665 Navigate Class/File/Symbol, Find in Path popup windows don't pick characters from input method
diff --git a/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java b/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
index eef5284..7842e0f 100644
--- a/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
+++ b/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
@@ -288,6 +288,18 @@
             if (component.getInputMethodRequests() == null) {
                 imInstance = null;
             }
+
+            LWWindowPeer windowPeer = peer.getPlatformWindow().getPeer();
+            if (windowPeer.isSimpleWindow()) {
+                // A simple window gains focus. Cocoa won't dispatch IME events into the simple window, but into its owner.
+                // This IM represents the focused component in the simple window. We will use the owner as IME proxy.
+                // For that, this IM is set for the owner and is dropped for the simple window.
+                Window owner = windowPeer.getTarget().getOwner();
+                assert owner != null && owner.isActive();
+                long ownerPtr = getNativeViewPtr((LWComponentPeer)owner.getPeer());
+                nativeNotifyPeer(ownerPtr, this);
+                imInstance = null;
+            }
         }
 
         if (peer != null) {
@@ -364,6 +376,14 @@
         fAwtFocussedComponentPeer = null;
     }
 
+    private boolean isValid() {
+        return  fIMContext != null &&
+                fAwtFocussedComponent != null &&
+                fAwtFocussedComponentPeer != null &&
+                fCurrentText != null &&
+                fCurrentTextAsString != null;
+    }
+
     /**
         * Returns a control object from this input method, or null. A
      * control object provides methods that control the behavior of the
@@ -580,9 +600,10 @@
      * substring.
      */
     synchronized private String attributedSubstringFromRange(final int locationIn, final int lengthIn) {
-        final String[] retString = new String[1];
+        final String[] retString = new String[] {""};
 
         try {
+            if (isValid())
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(retString) {
                     int location = locationIn;
@@ -635,6 +656,7 @@
         final int[] returnValue = new int[2];
 
         try {
+            if (isValid())
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(returnValue) {
                     AttributedCharacterIterator theIterator = fIMContext.getSelectedText(null);
@@ -710,6 +732,7 @@
         final int[] rect = new int[4];
 
         try {
+            if (isValid())
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(rect) {
                     int insertOffset = fIMContext.getInsertPositionOffset();
@@ -754,6 +777,7 @@
         final int[] insertPositionOffset = new int[1];
 
         try {
+            if (isValid())
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(offsetInfo) {
                     offsetInfo[0] = fIMContext.getLocationOffset(screenX, screenY);