IDEA-157673 After opening Preferences first time, controls are not editable, closing dialog leads to it be shown again. + exception thrown

The problem is that a type-ahead callback is set so that to block focus change until "Preferences" dialog receives WINDOW_ACTIVATED. But the event is not sent due to a bug in JDK.

The bug in JDK is specific to showing a modal dialog on OSX. Before calling peer.setVisible(true) in Dialog.conditionalShow(), the code which establishes modal blocking is executed, where the dialog's peer is ordered above the blocked windows. For that, native methods like "orderFrontRegardless" are called making the platform window be actually shown. So, the fact is that a modal dialog may be shown before it is expected. This triggers native focus change immediately, at the time the dialog's peer is not fully initialized yet. Namely, its "targetFocusable" property still has default "false" value, making the isFocusableWindowState() method return false. The latter leads to rejecting the focus change for the dialog and thus the focus events are lost.

A simple fix is to initialize "targetFocusable" on the peer creation. This is harmless, as the field only serves a cache for the target's focusability value.
1 file changed