-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b128
-
x86
-
windows_xp
-
Verified
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
There appears to be an undocumented bad intereaction between
explicitely setting the UI and removing all file filters, even temporarily.
If the latter is done before setting the ui, trying to display a file dialog
will throw an exception but not if the ui was set prior to messing with
the filters. Maybe it is possible to make the code more robust against
this or to include a warning in the docs?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program: it will not bomb. Then move the setUI
line to the bottom of the constructor and try again: it will.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(MetalFileChooserUI.java:1628)
at javax.swing.SwingUtilities.layoutCompoundLabelImpl(SwingUtilities.java:842)
at javax.swing.SwingUtilities.layoutCompoundLabel(SwingUtilities.java:769)
at javax.swing.plaf.basic.BasicLabelUI.layoutCL(BasicLabelUI.java:56)
at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:214)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
at javax.swing.plaf.basic.BasicComboBoxUI.getSizeForComponent(BasicComboBoxUI.java:1312)
at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(BasicComboBoxUI.java:1275)
at javax.swing.plaf.metal.MetalComboBoxUI.getMinimumSize(MetalComboBoxUI.java:181)
at javax.swing.plaf.basic.BasicComboBoxUI.getPreferredSize(BasicComboBoxUI.java:959)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:572)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:577)
at javax.swing.plaf.metal.MetalFileChooserUI.getPreferredSize(MetalFileChooserUI.java:1170)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:572)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:820)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:572)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at java.awt.Window.pack(Window.java:438)
at javax.swing.JFileChooser.createDialog(JFileChooser.java:748)
at javax.swing.JFileChooser.showDialog(JFileChooser.java:687)
at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:599)
at Bug7.main(Bug7.java:24)
Exception in thread "main"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.plaf.metal.MetalFileChooserUI;
import javax.swing.filechooser.FileFilter;
public class Bug7 extends JFileChooser {
private FileFilter any = new FileFilter() {
public boolean accept(File f) { return true; }
public String getDescription() { return "Any file"; } };
public Bug7() {
super();
setUI(new MetalFileChooserUI(this));
// we remove all built-in file filters
FileFilter[] ff = getChoosableFileFilters();
for (int i = 0; i < ff.length; i++)
removeChoosableFileFilter(ff[i]);
// we add a new one of our own, so the list is not empty
addChoosableFileFilter(any);
}
public static final void main(String[] argv) {
new Bug7().showOpenDialog(null);
}
}
---------- END SOURCE ----------
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
There appears to be an undocumented bad intereaction between
explicitely setting the UI and removing all file filters, even temporarily.
If the latter is done before setting the ui, trying to display a file dialog
will throw an exception but not if the ui was set prior to messing with
the filters. Maybe it is possible to make the code more robust against
this or to include a warning in the docs?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program: it will not bomb. Then move the setUI
line to the bottom of the constructor and try again: it will.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(MetalFileChooserUI.java:1628)
at javax.swing.SwingUtilities.layoutCompoundLabelImpl(SwingUtilities.java:842)
at javax.swing.SwingUtilities.layoutCompoundLabel(SwingUtilities.java:769)
at javax.swing.plaf.basic.BasicLabelUI.layoutCL(BasicLabelUI.java:56)
at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:214)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
at javax.swing.plaf.basic.BasicComboBoxUI.getSizeForComponent(BasicComboBoxUI.java:1312)
at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(BasicComboBoxUI.java:1275)
at javax.swing.plaf.metal.MetalComboBoxUI.getMinimumSize(MetalComboBoxUI.java:181)
at javax.swing.plaf.basic.BasicComboBoxUI.getPreferredSize(BasicComboBoxUI.java:959)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:572)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:577)
at javax.swing.plaf.metal.MetalFileChooserUI.getPreferredSize(MetalFileChooserUI.java:1170)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:572)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:820)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:572)
at java.awt.Container.preferredSize(Container.java:1178)
at java.awt.Container.getPreferredSize(Container.java:1162)
at java.awt.Window.pack(Window.java:438)
at javax.swing.JFileChooser.createDialog(JFileChooser.java:748)
at javax.swing.JFileChooser.showDialog(JFileChooser.java:687)
at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:599)
at Bug7.main(Bug7.java:24)
Exception in thread "main"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.plaf.metal.MetalFileChooserUI;
import javax.swing.filechooser.FileFilter;
public class Bug7 extends JFileChooser {
private FileFilter any = new FileFilter() {
public boolean accept(File f) { return true; }
public String getDescription() { return "Any file"; } };
public Bug7() {
super();
setUI(new MetalFileChooserUI(this));
// we remove all built-in file filters
FileFilter[] ff = getChoosableFileFilters();
for (int i = 0; i < ff.length; i++)
removeChoosableFileFilter(ff[i]);
// we add a new one of our own, so the list is not empty
addChoosableFileFilter(any);
}
public static final void main(String[] argv) {
new Bug7().showOpenDialog(null);
}
}
---------- END SOURCE ----------
- relates to
-
JDK-7012804 Some code of the JFileChooser#updateUI method should be moved into their setUI method
- Closed