JRE-989 backport JRE-981: IM workaround does not work anymore

(cherry picked from commit 2d7c29b0abab252167399fb41eb04689d3a4f2f6)
diff --git a/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java b/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
index 7842e0f..be127c2 100644
--- a/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
+++ b/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
@@ -376,14 +376,6 @@
         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
@@ -603,7 +595,7 @@
         final String[] retString = new String[] {""};
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(retString) {
                     int location = locationIn;
@@ -656,7 +648,7 @@
         final int[] returnValue = new int[2];
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(returnValue) {
                     AttributedCharacterIterator theIterator = fIMContext.getSelectedText(null);
@@ -732,7 +724,7 @@
         final int[] rect = new int[4];
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(rect) {
                     int insertOffset = fIMContext.getInsertPositionOffset();
@@ -751,7 +743,7 @@
                     if (composedTextOffset > 0 && (fAwtFocussedComponent instanceof JTextComponent)) {
                         Rectangle r2 = fIMContext.getTextLocation(TextHitInfo.beforeOffset(0));
 
-                        if (r.equals(r2)) {
+                        if (r.equals(r2) && fCurrentTextAsString != null) {
                             // FIXME: (SAK) If the candidate text wraps over two lines, this calculation pushes the candidate
                             // window off the right edge of the component.
                             String inProgressSubstring = fCurrentTextAsString.substring(0, composedTextOffset);
@@ -777,7 +769,7 @@
         final int[] insertPositionOffset = new int[1];
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(offsetInfo) {
                     offsetInfo[0] = fIMContext.getLocationOffset(screenX, screenY);