-
Bug
-
Resolution: Fixed
-
P4
-
5.0
-
b23
-
x86
-
windows_xp
FULL PRODUCT VERSION :
ADDITIONAL OS VERSION INFORMATION :
Windows XP
A DESCRIPTION OF THE PROBLEM :
The getUIError method should only throw the exception. The first line -
System.err.println("UIDefatuls.getUI() failed: " + msg);
should be deleted.
1) It is redundant, since the runtime error can be displayed anyway.
2) It makes it impossible for Swing applications to catch the error and to take corrective action without having System.err cluttered up.
For example
public void updateUI() {
if(UIManager.getUI(this) == null) {
// take recovery actions
}
setUI(UIManager.getUI(this));
}
ends up displaying the error traceback to the console regardless of any additional exception catching code you may add.
Som additional comments:
1) Why should UIManager.getUI() throw a runtime exception (indirectly, through UIDefaults.getUIError)? It seems to me that it should just return null if it can't find the ComponentUI class.
2) The JavaDoc implies that getUIError behavior can be changed by overriding. In fact (as has been pointed out in another bug report), this is difficult or impossible.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Install custom UI. Change laf with UIManager.setLookAndFeel. Eventually, the updateUI method of your class (with custom UI) is called. UIManager.getUI then dumps to System.err.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected UIManager.getUI to return null, or at worst to throw a catchable exception without dumping to System.err.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
UIDefaults.getUI() failed: no ComponentUI class for: <MY_SWING_CLASS>
java.lang.Error
at javax.swing.UIDefaults.getUIError(UIDefaults.java:689)
at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:117)
at javax.swing.UIDefaults.getUI(UIDefaults.java:719)
at javax.swing.UIManager.getUI(UIManager.java:860)
at MY_SWING_CLASS.updateUI(EventTable.java:261)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1146)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI(SwingUtilities.java:1138)
at casper.client.gui.UISwitchListener.propertyChange(UISwitchListener.java:64)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:450)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:477)
at <MY CONTROLLER CLASS THAT CALLS setLookAndFeel>
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Do not call UIManager.getUI(this) in your updateUI method. Instead use something like
public void updateUI() {
// Don't do this
// if(UIManager.getUI(this) == null) {
// // take recovery actions
// }
// Do this instead
ClassLoader uiClassLoader = getClass().getClassLoader();
Class uiClass = UIManager.getDefaults().getUIClass(getUIClassID(), uiClassLoader);
if(uiClass == null) {
// take recovery actions
}
setUI(UIManager.getUI(this));
}
###@###.### 2005-05-09 06:10:48 GMT
ADDITIONAL OS VERSION INFORMATION :
Windows XP
A DESCRIPTION OF THE PROBLEM :
The getUIError method should only throw the exception. The first line -
System.err.println("UIDefatuls.getUI() failed: " + msg);
should be deleted.
1) It is redundant, since the runtime error can be displayed anyway.
2) It makes it impossible for Swing applications to catch the error and to take corrective action without having System.err cluttered up.
For example
public void updateUI() {
if(UIManager.getUI(this) == null) {
// take recovery actions
}
setUI(UIManager.getUI(this));
}
ends up displaying the error traceback to the console regardless of any additional exception catching code you may add.
Som additional comments:
1) Why should UIManager.getUI() throw a runtime exception (indirectly, through UIDefaults.getUIError)? It seems to me that it should just return null if it can't find the ComponentUI class.
2) The JavaDoc implies that getUIError behavior can be changed by overriding. In fact (as has been pointed out in another bug report), this is difficult or impossible.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Install custom UI. Change laf with UIManager.setLookAndFeel. Eventually, the updateUI method of your class (with custom UI) is called. UIManager.getUI then dumps to System.err.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected UIManager.getUI to return null, or at worst to throw a catchable exception without dumping to System.err.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
UIDefaults.getUI() failed: no ComponentUI class for: <MY_SWING_CLASS>
java.lang.Error
at javax.swing.UIDefaults.getUIError(UIDefaults.java:689)
at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:117)
at javax.swing.UIDefaults.getUI(UIDefaults.java:719)
at javax.swing.UIManager.getUI(UIManager.java:860)
at MY_SWING_CLASS.updateUI(EventTable.java:261)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1146)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1157)
at javax.swing.SwingUtilities.updateComponentTreeUI(SwingUtilities.java:1138)
at casper.client.gui.UISwitchListener.propertyChange(UISwitchListener.java:64)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:450)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:477)
at <MY CONTROLLER CLASS THAT CALLS setLookAndFeel>
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Do not call UIManager.getUI(this) in your updateUI method. Instead use something like
public void updateUI() {
// Don't do this
// if(UIManager.getUI(this) == null) {
// // take recovery actions
// }
// Do this instead
ClassLoader uiClassLoader = getClass().getClassLoader();
Class uiClass = UIManager.getDefaults().getUIClass(getUIClassID(), uiClassLoader);
if(uiClass == null) {
// take recovery actions
}
setUI(UIManager.getUI(this));
}
###@###.### 2005-05-09 06:10:48 GMT