Bug 228890 - [Commands] WidgetMethodHandler should not use obsolete Swing API any when possible
Summary: [Commands] WidgetMethodHandler should not use obsolete Swing API any when pos...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard: hasPatch
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-04-25 11:27 EDT by Bruno Haible CLA
Modified: 2008-05-06 15:40 EDT (History)
2 users (show)

See Also:
eclipse: review+


Attachments
tentative fix (3.19 KB, patch)
2008-04-25 11:29 EDT, Bruno Haible CLA
no flags Details | Diff
Widget fix v02 (13.48 KB, patch)
2008-05-06 14:48 EDT, Paul Webster CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Haible CLA 2008-04-25 11:27:56 EDT
The class org.eclipse.ui.internal.handlers.WidgetMethodHandler uses some focus API from before JRE 1.4, namely javax.swing.FocusManager. The implementation of this class and the DefaultFocusManager have these javadoc comments:

 * This class has been obsoleted by the 1.4 focus APIs. While client code may
 * still use this class, developers are strongly encouraged to use
 * <code>java.awt.KeyboardFocusManager</code> and
 * <code>java.awt.DefaultKeyboardFocusManager</code> instead. Please see the
 * Focus Specification for more information.

Additionally, the DefaultFocusManager installs an instance of LegacyGlueFocusTraversalPolicy, which causes endless recursions when other plugins use the JRE 1.4 focus APIs.

We have seen such endless recursions in the context of the Eclipse Albireo project (http://wiki.eclipse.org/Albireo_Project):

...
java.awt.ContainerOrderFocusTraversalPolicy.getLastComponent(ContainerOrderFocusTraversalPolicy.java:366)
javax.swing.DefaultFocusManager.getLastComponent(DefaultFocusManager.java:119)
javax.swing.LegacyGlueFocusTraversalPolicy.getLastComponent(LegacyGlueFocusTraversalPolicy.java:124)
java.awt.ContainerOrderFocusTraversalPolicy.getLastComponent(ContainerOrderFocusTraversalPolicy.java:366)
...

It would be better if Eclipse did not cause this LegacyGlueFocusTraversalPolicy to be installed.

Patch attached.
Comment 1 Bruno Haible CLA 2008-04-25 11:29:34 EDT
Created attachment 97624 [details]
tentative fix
Comment 2 Bruno Haible CLA 2008-04-25 11:56:30 EDT
The stack trace of the activation of this troublesome LegacyGlueFocusTraversalPolicy is like this:

LegacyGlueFocusTraversalPolicy.<init>(DefaultFocusManager) line: 41	
DelegatingDefaultFocusManager(DefaultFocusManager).<init>() line: 34	
DelegatingDefaultFocusManager.<init>(KeyboardFocusManager) line: 26	
FocusManager.getCurrentManager() line: 62	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
Method.invoke(Object, Object...) line: 585	
WidgetMethodHandler.getFocusComponent() line: 175	
WidgetMethodHandler.getMethodToExecute() line: 217	
WidgetMethodHandler.isEnabled() line: 184	
Comment 3 Paul Webster CLA 2008-05-06 14:48:55 EDT
Created attachment 98914 [details]
Widget fix v02

Minor updates including a copyright update
PW
Comment 4 Paul Webster CLA 2008-05-06 14:50:47 EDT
Kim, could you please review for a +1

Thanx,
PW
Comment 5 Kim Horne CLA 2008-05-06 14:55:14 EDT
Just to be clear,  all of the interesting changes are in getFocusComponent()?  There are a lot of formatting changes in that patch... 

as for getFocusComponent(), is it possible for any of the calls to KeyboardFocusManager to return null?  Should there be a try/catch there as well with a graceful degradation to the old behaviour?
Comment 6 Paul Webster CLA 2008-05-06 15:04:24 EDT
(In reply to comment #5)
> Just to be clear,  all of the interesting changes are in getFocusComponent()? 
> There are a lot of formatting changes in that patch... 

Nuts, I must have ignore whitespace turned on by default.

> as for getFocusComponent(), is it possible for any of the calls to
> KeyboardFocusManager to return null?  Should there be a try/catch there as well
> with a graceful degradation to the old behaviour?
> 

It is possible for getFocusOwner() to return null ... but that indicates there is no component in focus and it is valid for us to return null from the method.  I'm pretty sure we don't want to fall back to the old way (which should also return null in this case).


PW
Comment 7 Kim Horne CLA 2008-05-06 15:10:40 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > Just to be clear,  all of the interesting changes are in getFocusComponent()? 
> > There are a lot of formatting changes in that patch... 
> 
> Nuts, I must have ignore whitespace turned on by default.
> 
> > as for getFocusComponent(), is it possible for any of the calls to
> > KeyboardFocusManager to return null?  Should there be a try/catch there as well
> > with a graceful degradation to the old behaviour?
> > 
> 
> It is possible for getFocusOwner() to return null ... but that indicates there
> is no component in focus and it is valid for us to return null from the method.
>  I'm pretty sure we don't want to fall back to the old way (which should also
> return null in this case).
> 
> 
> PW
> 

I was more concerned with getCurrentKeyboardFocusManager... 
Comment 8 Paul Webster CLA 2008-05-06 15:13:50 EDT
(In reply to comment #7)
> 
> I was more concerned with getCurrentKeyboardFocusManager... 
> 

No, that instantiates and/or returns the singleton

PW
Comment 9 Kim Horne CLA 2008-05-06 15:20:39 EDT
+1
Comment 10 Paul Webster CLA 2008-05-06 15:40:05 EDT
Bruno, could you verify this on Thursday using the I20080507-2000 I  build?

Released to HEAD

PW