JDK-6833019 : KeyboardFocusManager.getCurrentKeyboardFocusManager() throws unspecified HeadlessException
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: generic
  • Submitted: 2009-04-22
  • Updated: 2012-03-22
  • Resolved: 2011-03-07
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 7
7 b60Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
The fix for 6806217 introduced the following failure reported in SDN comments.

The testcase:

public class Failure {
  public static void main(String[] args) {
    java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager();
  }
}

The problem:

java -showversion -Djava.awt.headless=true Failure
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b55)
Java HotSpot(TM) 64-Bit Server VM (build 15.0-b05, mixed mode)

Exception in thread "main" java.awt.HeadlessException
	at sun.awt.HeadlessToolkit.createKeyboardFocusManagerPeer(HeadlessToolkit.java:184)
	at java.awt.KeyboardFocusManager.initPeer(KeyboardFocusManager.java:454)
	at java.awt.KeyboardFocusManager.<init>(KeyboardFocusManager.java:448)
	at java.awt.DefaultKeyboardFocusManager.<init>(DefaultKeyboardFocusManager.java:64)
	at java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager(KeyboardFocusManager.java:218)
	at java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager(KeyboardFocusManager.java:209)
	at Failure.main(Failure.java:3)

Comments
SUGGESTED FIX src/share/classes/sun/awt/HeadlessToolkit.java Print this page @@ -177,13 +177,19 @@ public RobotPeer createRobot(Robot target, GraphicsDevice screen) throws AWTException, HeadlessException { throw new HeadlessException(); } - public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) - throws HeadlessException { - throw new HeadlessException(); + public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) { + // See 6833019. + return + new KeyboardFocusManagerPeer() { + public Window getCurrentFocusedWindow() { return null; } + public void setCurrentFocusOwner(Component comp) {} + public Component getCurrentFocusOwner() { return null; } + public void clearGlobalFocusOwner(Window activeWindow) {} + }; } public TrayIconPeer createTrayIcon(TrayIcon target) throws HeadlessException { throw new HeadlessException();
21-05-2009

EVALUATION As a solution, a dummy KFM peer is created in the headless mode.
21-05-2009

EVALUATION So, the problem is that the method has started to throw HeadlessException in the headless mode and the exception is not mentioned in the javadoc. Nevertheless KeyboardFocusManager is useless in the headless mode, the client code that (for some reason) calls that method is broken. We might return null at least to provide some backward compatibility.
22-04-2009