JDK-8179665 : [Windows] java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u131,9
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: x86_64
  • Submitted: 2017-05-04
  • Updated: 2018-05-23
  • Resolved: 2017-05-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 8 JDK 9 Other
10Fixed 8u152Fixed 9 b172Fixed openjdk7uFixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
If a modal dialog is made visible after its parent frame is set to always-on-top, closed by hitting the "Enter" key which activates a default button, then the parent frame is set to not-always-on-top, an IllegalComponentStateException is raised.

The stack dump looks the same as in http://bugs.java.com/view_bug.do?bug_id=8159242, though the description of that bug doesn't seem to have anything to do with the stack dump.

There is good reason to set the dialog's frame parent to always-on-top while it is up, if the dialog itself is always-on-top. If another modal dialog pops up while it is up, that other dialog may otherwise be hidden, and the application will appear to be locked up. There are also good reasons to make all modal dialogs always-on-top.

REGRESSION.  Last worked in version 8u121

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run code, hit "Enter" to close the dialog.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect no exceptions.
ACTUAL -
An IllegalComponentStateException occurs.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
	at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:2062)
	at java.awt.Component.getLocationOnScreen(Component.java:2036)
	at javax.swing.text.JTextComponent$InputMethodRequestsHandler.getTextLocation(JTextComponent.java:4643)
	at sun.awt.im.InputMethodContext.getTextLocation(InputMethodContext.java:278)
	at sun.awt.windows.WInputMethod$1.run(WInputMethod.java:588)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
	at java.awt.EventQueue$4.run(EventQueue.java:731)
	at java.awt.EventQueue$4.run(EventQueue.java:729)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class ICSEBug {

   public static void main(String[] args) {
      SwingUtilities.invokeLater(
         new Runnable() {
            public void run() {
               go();
            }
         });
   }

   static void go() {
      JFrame f = new JFrame();
      f.setVisible(true);
      final JDialog d = new JDialog(f);
      d.getContentPane().add(new JTextField(20), "Center");
      JButton closeButton = new JButton("Close");
      closeButton.addActionListener(
         new ActionListener() {
            public void actionPerformed(ActionEvent e) {
               d.setVisible(false);
            }
         });
      d.getContentPane().add(closeButton, "South");
      d.getRootPane().setDefaultButton(closeButton);
      d.setModal(true);
      d.setSize(300, 300);
      f.setAlwaysOnTop(true);
      d.setVisible(true);
      f.setAlwaysOnTop(false);
   }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
If the exception is caught in a global uncaught exception handler, it can be ignored. It doesn't seem to cause any problems.


Comments
We continue receiving more reports from users affected with this issue in 8u: https://bugs.openjdk.java.net/browse/JDK-8186432
18-08-2017

It is our intention to request a backport to 8u-dev and if that is accepted, follow it up with a request to get it into an update release ASAP.
19-05-2017

Will this be fixed also in next JDK8 Update release? It will be beneficial for many products.
19-05-2017

Fix Request: This is a regression: an exception may be thrown in some circumstances when a window is closed and set-always-on top state is cleared on its parent immediately after that. The fix skips calculation of the location of the IME popup if the window it belongs is in hidden state. The fix doesn't change any actually used data (when a window is in hidden state its IME popup location doesn't matter). The risk may be assumed as minimal. A new regression test is provided. It simulates the bug scenario and fails if the exception occurred. webrev: http://cr.openjdk.java.net/~ssadetsky/8179665/webrev.01/ (reviewed by prr and serb)
18-05-2017

Under review: http://mail.openjdk.java.net/pipermail/awt-dev/2017-May/012850.html
18-05-2017

Affects also NetBeans IDE with many duplicates already filled https://netbeans.org/bugzilla/show_bug.cgi?id=270487
15-05-2017

The issue is caused by the JDK-8147842 but is not a direct regression of it. Setting always-on-top state to false for a window causes clearing of this state for all its child (owned) windows. On Windows platform windows maintain their always-on-top state even when invisible. Windows receive IME status window notifications when always-on-top state is changed. Before the JDK-8147842, the IME status window position was not calculated at all. But now the position is calculated and causes IllegalComponentStateException because the parent window is not visible.
08-05-2017

Below are the result == 8u121 - Pass 8u131 - Fail 9 ea b123 - Pass 9 ea b124 - Fail 9 ea b168 - Fail Most likely issue is introduced by JDK-8147842
05-05-2017

This is a regression started from 8u131 and 9 ea b124.
05-05-2017

Issue is reproducible only on Windows == C:\Users\fmatte.ORADEV\Desktop>d:\JAVA\jdk1.8.0_131\bin\javac.exe ICSEBug.java C:\Users\fmatte.ORADEV\Desktop>d:\JAVA\jdk1.8.0_131\bin\java.exe ICSEBug Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:2062) at java.awt.Component.getLocationOnScreen(Component.java:2036) at javax.swing.text.JTextComponent$InputMethodRequestsHandler.getTextLocation(JTextComponent.java:4643) at sun.awt.im.InputMethodContext.getTextLocation(InputMethodContext.java:278) at sun.awt.windows.WInputMethod$1.run(WInputMethod.java:588) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) C:\Users\fmatte.ORADEV\Desktop>"d:\Program Files\Java\jdk1.8.0_121\bin\javac.exe" ICSEBug.java C:\Users\fmatte.ORADEV\Desktop>"d:\Program Files\Java\jdk1.8.0_121\bin\java.exe" ICSEBug ==
04-05-2017