-
Bug
-
Resolution: Fixed
-
P4
-
5.0
-
b19
-
x86
-
windows_xp
FULL PRODUCT VERSION :
JDK 1.5.0_10
ADDITIONAL OS VERSION INFORMATION :
WinXP 5.1.2600, Solaris 5.10
A DESCRIPTION OF THE PROBLEM :
When setting a JFileChooser to an instance of a FileView subclass that restricts traversing outside of a specified directory tree, and I use the pulldown list to select a directory outside of the tree, and then do it again to select a directory inside the tree, a NullPointerException is thrown from inside JFileChooser.
A toy program and stack trace are included below wbjch demonstrate this (with the path changed for Solaris).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the toy program below on Windows (make sure C:\temp exists) - in the JFileChooser, use the pulldown list to choose the C:\ drive or some other directory; then, use the pulldown again to choose C:\temp. Verify the NullPointerException at the console.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception occurred during event dispatching:
java.lang.NullPointerException
at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxAction.actionPerformed(Unknown Source)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at javax.swing.JFileChooser.showDialog(Unknown Source)
at javax.swing.JFileChooser.showOpenDialog(Unknown Source)
at FileChooserTest$1.actionPerformed(FileChooserTest.java:28)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileView;
public class FileChooserTest extends JFrame {
private JButton button = null;
public static void main(String [] args) {
FileChooserTest application = new FileChooserTest();
application.setVisible(true);
}
public FileChooserTest() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(200, 200);
button = new JButton("Show Chooser");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser openChooser = new JFileChooser();
String path = "C:" + File.separator + "temp";
openChooser.setCurrentDirectory(new File(path));
openChooser.setFileView(new MyFileView(path));
int result = openChooser.showOpenDialog(FileChooserTest.this);
if (result == JFileChooser.APPROVE_OPTION)
System.out.println(openChooser.getSelectedFile().getAbsolutePath());
else
System.out.println("cancelled");
}
});
getContentPane().setLayout(new BorderLayout());
getContentPane().add(button, BorderLayout.CENTER);
}
}
class MyFileView extends FileView {
private String basePath;
public MyFileView(String path) {
basePath = path;
}
public Boolean isTraversable(File f) {
if ((f != null) && (f.isDirectory()))
return f.getAbsolutePath().startsWith(basePath);
else
return false;
}
}
---------- END SOURCE ----------
JDK 1.5.0_10
ADDITIONAL OS VERSION INFORMATION :
WinXP 5.1.2600, Solaris 5.10
A DESCRIPTION OF THE PROBLEM :
When setting a JFileChooser to an instance of a FileView subclass that restricts traversing outside of a specified directory tree, and I use the pulldown list to select a directory outside of the tree, and then do it again to select a directory inside the tree, a NullPointerException is thrown from inside JFileChooser.
A toy program and stack trace are included below wbjch demonstrate this (with the path changed for Solaris).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the toy program below on Windows (make sure C:\temp exists) - in the JFileChooser, use the pulldown list to choose the C:\ drive or some other directory; then, use the pulldown again to choose C:\temp. Verify the NullPointerException at the console.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception occurred during event dispatching:
java.lang.NullPointerException
at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxAction.actionPerformed(Unknown Source)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at javax.swing.JFileChooser.showDialog(Unknown Source)
at javax.swing.JFileChooser.showOpenDialog(Unknown Source)
at FileChooserTest$1.actionPerformed(FileChooserTest.java:28)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileView;
public class FileChooserTest extends JFrame {
private JButton button = null;
public static void main(String [] args) {
FileChooserTest application = new FileChooserTest();
application.setVisible(true);
}
public FileChooserTest() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(200, 200);
button = new JButton("Show Chooser");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser openChooser = new JFileChooser();
String path = "C:" + File.separator + "temp";
openChooser.setCurrentDirectory(new File(path));
openChooser.setFileView(new MyFileView(path));
int result = openChooser.showOpenDialog(FileChooserTest.this);
if (result == JFileChooser.APPROVE_OPTION)
System.out.println(openChooser.getSelectedFile().getAbsolutePath());
else
System.out.println("cancelled");
}
});
getContentPane().setLayout(new BorderLayout());
getContentPane().add(button, BorderLayout.CENTER);
}
}
class MyFileView extends FileView {
private String basePath;
public MyFileView(String path) {
basePath = path;
}
public Boolean isTraversable(File f) {
if ((f != null) && (f.isDirectory()))
return f.getAbsolutePath().startsWith(basePath);
else
return false;
}
}
---------- END SOURCE ----------
- relates to
-
JDK-8295298 Automate javax/swing/JFileChooser/FileViewNPETest.java
-
- Resolved
-